Initial commit
This commit is contained in:
21
node_modules/node-blockly/blockly/tests/blocks/index.html
generated
vendored
Normal file
21
node_modules/node-blockly/blockly/tests/blocks/index.html
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Unit Tests for Blockly Blocks</title>
|
||||
<script src="../../blockly_compressed.js"></script>
|
||||
<script src="../../msg/js/en.js"></script> <!-- TODO: Test messages in all languages. -->
|
||||
<script src="../../blocks/colour.js"></script>
|
||||
<script src="../../blocks/lists.js"></script>
|
||||
<script src="../../blocks/logic.js"></script>
|
||||
<script src="../../blocks/loops.js"></script>
|
||||
<script src="../../blocks/math.js"></script>
|
||||
<script src="../../blocks/procedures.js"></script>
|
||||
<script src="../../blocks/text.js"></script>
|
||||
<script src="../../blocks/variables.js"></script>
|
||||
<script>goog.require('goog.testing.jsunit');</script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="logic_ternary_test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
316
node_modules/node-blockly/blockly/tests/blocks/logic_ternary_test.js
generated
vendored
Normal file
316
node_modules/node-blockly/blockly/tests/blocks/logic_ternary_test.js
generated
vendored
Normal file
@@ -0,0 +1,316 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_logic_ternary_structure() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
assertEquals(3, block.inputList && block.inputList.length);
|
||||
assertEquals(1, block.getInput('IF').connection.check_.length);
|
||||
assertEquals('Boolean', block.getInput('IF').connection.check_[0]);
|
||||
assertTrue(!!block.onchangeWrapper_); // Has onchange handler
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachSameTypeCheckInThenAndElseWithoutParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
|
||||
var string1 = workspace.newBlock('text');
|
||||
var string2 = workspace.newBlock('text_charAt');
|
||||
|
||||
block.getInput('THEN').connection.connect(string1.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string1.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(string2.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string1.getRootBlock()); // Still connected.
|
||||
assertEquals(block, string2.getRootBlock());
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachDifferectTypeChecksInThenAndElseWithoutParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachSameTypeCheckInThenAndElseWithMatchingParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var parent = workspace.newBlock('text_trim');
|
||||
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
assertEquals(parent, block.getRootBlock());
|
||||
|
||||
var string1 = workspace.newBlock('text');
|
||||
var string2 = workspace.newBlock('text_charAt');
|
||||
|
||||
block.getInput('THEN').connection.connect(string1.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string1.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(string2.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string1.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(parent, string2.getRootBlock());
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachDifferectTypeChecksInThenAndElseWithUncheckedParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var parent = workspace.newBlock('text_print');
|
||||
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
assertEquals(parent, block.parentBlock_);
|
||||
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(parent, number.getRootBlock());
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachDifferectTypeChecksInThenAndElseWithPermissiveParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var parent = workspace.newBlock('text_length'); // Allows String or Array
|
||||
|
||||
parent.getInput('VALUE').connection.connect(block.outputConnection);
|
||||
assertEquals(parent, block.parentBlock_);
|
||||
|
||||
var string = workspace.newBlock('text');
|
||||
var array = workspace.newBlock('lists_create_empty');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(array.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(parent, array.getRootBlock());
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachMismatchTypeToThen_breakWithParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var parent = workspace.newBlock('text_length'); // Allows String or Array
|
||||
|
||||
parent.getInput('VALUE').connection.connect(block.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.parentBlock_);
|
||||
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('ELSE').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock());
|
||||
|
||||
// Adding mismatching number.
|
||||
block.getInput('THEN').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, block.getRootBlock()); // Disconnected from parent.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
assertEquals(block, string.getRootBlock()); // ELSE string still connected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachMismatchTypeToElse_breakWithParent() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var parent = workspace.newBlock('text_length'); // Allows String or Array
|
||||
|
||||
parent.getInput('VALUE').connection.connect(block.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.parentBlock_);
|
||||
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Still connected to parent.
|
||||
assertEquals(parent, string.getRootBlock());
|
||||
|
||||
// Adding mismatching number.
|
||||
block.getInput('ELSE').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, block.getRootBlock()); // Disconnected from parent.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
assertEquals(block, string.getRootBlock()); // THEN string still connected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachToUncheckedParentWithDifferentTypes() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
|
||||
// Attaching to parent.
|
||||
var parent = workspace.newBlock('text_print');
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
assertEquals(parent, block.getRootBlock());
|
||||
assertEquals(parent, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(parent, number.getRootBlock()); // Input ELSE still connected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachToPermissiveParentWithDifferentTypes() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var string = workspace.newBlock('text');
|
||||
var array = workspace.newBlock('lists_create_empty');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(array.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(block, array.getRootBlock());
|
||||
|
||||
// Attaching to parent.
|
||||
var parent = workspace.newBlock('text_print');
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock());
|
||||
assertEquals(parent, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(parent, array.getRootBlock()); // Input ELSE still connected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachToParentWithMismatchingThen_disconnectThen() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var number = workspace.newBlock('math_number');
|
||||
var string = workspace.newBlock('text');
|
||||
|
||||
block.getInput('THEN').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, number.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(block, string.getRootBlock());
|
||||
|
||||
// Attaching to parent.
|
||||
var parent = workspace.newBlock('text_trim');
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Successful connection to parent.
|
||||
assertEquals(parent, string.getRootBlock()); // Input ELSE still connected.
|
||||
assertEquals(number, number.getRootBlock()); // Input THEN disconnected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_logic_ternary_attachToParentWithMismatchingElse_disconnectElse() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var block = workspace.newBlock('logic_ternary');
|
||||
var string = workspace.newBlock('text');
|
||||
var number = workspace.newBlock('math_number');
|
||||
|
||||
block.getInput('THEN').connection.connect(string.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock());
|
||||
block.getInput('ELSE').connection.connect(number.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(block, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(block, number.getRootBlock());
|
||||
|
||||
// Attaching to parent.
|
||||
var parent = workspace.newBlock('text_trim');
|
||||
parent.getInput('TEXT').connection.connect(block.outputConnection);
|
||||
Blockly.Events.fireNow_(); // Force synchronous onchange() call.
|
||||
assertEquals(parent, block.getRootBlock()); // Successful connection to parent.
|
||||
assertEquals(parent, string.getRootBlock()); // Input THEN still connected.
|
||||
assertEquals(number, number.getRootBlock()); // Input ELSE disconnected.
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
525
node_modules/node-blockly/blockly/tests/blocks/test_blocks.js
generated
vendored
Normal file
525
node_modules/node-blockly/blockly/tests/blocks/test_blocks.js
generated
vendored
Normal file
@@ -0,0 +1,525 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([ // BEGIN JSON EXTRACT
|
||||
{
|
||||
"type": "empty_block",
|
||||
"message0": "",
|
||||
"args0": []
|
||||
},
|
||||
{
|
||||
"type": "example_dropdown_long",
|
||||
"message0": "long: %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "FIELDNAME",
|
||||
"options": [
|
||||
[ "first item", "ITEM1" ],
|
||||
[ "second item", "ITEM2" ],
|
||||
[ "third item", "ITEM3" ],
|
||||
[ "fourth item", "ITEM4" ],
|
||||
[ "fifth item", "ITEM5" ],
|
||||
[ "sixth item", "ITEM6" ],
|
||||
[ "seventh item", "ITEM7" ],
|
||||
[ "eighth item", "ITEM8" ],
|
||||
[ "ninth item", "ITEM9" ],
|
||||
[ "tenth item", "ITEM10" ],
|
||||
[ "eleventh item", "ITEM11" ],
|
||||
[ "twelfth item", "ITEM12" ],
|
||||
[ "thirteenth item", "ITEM13" ],
|
||||
[ "fourteenth item", "ITEM14" ],
|
||||
[ "fifteenth item", "ITEM15" ],
|
||||
[ "sixteenth item", "ITEM16" ],
|
||||
[ "seventeenth item", "ITEM17" ],
|
||||
[ "eighteenth item", "ITEM18" ],
|
||||
[ "nineteenth item", "ITEM19" ],
|
||||
[ "twentieth item", "ITEM20" ],
|
||||
[ "twenty-first item", "ITEM21" ],
|
||||
[ "twenty-second item", "ITEM22" ],
|
||||
[ "twenty-third item", "ITEM23" ],
|
||||
[ "twenty-fourth item", "ITEM24" ],
|
||||
[ "twenty-fifth item", "ITEM25" ],
|
||||
[ "twenty-sixth item", "ITEM26" ],
|
||||
[ "twenty-seventh item", "ITEM27" ],
|
||||
[ "twenty-eighth item", "ITEM28" ],
|
||||
[ "twenty-ninth item", "ITEM29" ],
|
||||
[ "thirtieth item", "ITEM30" ],
|
||||
[ "thirty-first item", "ITEM31" ],
|
||||
[ "thirty-second item", "ITEM32" ]
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "example_dropdown_images",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "FIELDNAME",
|
||||
"options": [
|
||||
[{"src": "../media/test_a.png", "width": 32, "height": 32, "alt": "A"}, "A"],
|
||||
[{"src": "../media/test_b.png", "width": 32, "height": 32, "alt": "B"}, "B"],
|
||||
[{"src": "../media/test_c.png", "width": 32, "height": 32, "alt": "C"}, "C"],
|
||||
[{"src": "../media/test_d.png", "width": 32, "height": 32, "alt": "D"}, "D"],
|
||||
[{"src": "../media/test_e.png", "width": 32, "height": 32, "alt": "E"}, "E"],
|
||||
[{"src": "../media/test_f.png", "width": 32, "height": 32, "alt": "F"}, "F"],
|
||||
[{"src": "../media/test_g.png", "width": 32, "height": 32, "alt": "G"}, "G"],
|
||||
[{"src": "../media/test_h.png", "width": 32, "height": 32, "alt": "H"}, "H"],
|
||||
[{"src": "../media/test_i.png", "width": 32, "height": 32, "alt": "I"}, "I"],
|
||||
[{"src": "../media/test_j.png", "width": 32, "height": 32, "alt": "J"}, "J"],
|
||||
[{"src": "../media/test_k.png", "width": 32, "height": 32, "alt": "K"}, "K"],
|
||||
[{"src": "../media/test_l.png", "width": 32, "height": 32, "alt": "L"}, "L"],
|
||||
[{"src": "../media/test_m.png", "width": 32, "height": 32, "alt": "M"}, "M"]
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "example_dropdown_images_and_text",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "FIELDNAME",
|
||||
"options": [
|
||||
["images and text", "IMAGES AND TEXT"],
|
||||
[{"src": "../media/test_a.png", "width": 32, "height": 32, "alt": "A"}, "A"],
|
||||
[{"src": "../media/test_b.png", "width": 32, "height": 32, "alt": "B"}, "B"],
|
||||
[{"src": "../media/test_c.png", "width": 32, "height": 32, "alt": "C"}, "C"],
|
||||
[{"src": "../media/test_d.png", "width": 32, "height": 32, "alt": "D"}, "D"],
|
||||
[{"src": "../media/test_e.png", "width": 32, "height": 32, "alt": "E"}, "E"],
|
||||
[{"src": "../media/test_f.png", "width": 32, "height": 32, "alt": "F"}, "F"],
|
||||
[{"src": "../media/test_g.png", "width": 32, "height": 32, "alt": "G"}, "G"],
|
||||
[{"src": "../media/test_h.png", "width": 32, "height": 32, "alt": "H"}, "H"],
|
||||
["xyz", "LMNOP"],
|
||||
[{"src": "../media/test_i.png", "width": 32, "height": 32, "alt": "I"}, "I"],
|
||||
[{"src": "../media/test_j.png", "width": 32, "height": 32, "alt": "J"}, "J"],
|
||||
[{"src": "../media/test_k.png", "width": 32, "height": 32, "alt": "K"}, "K"],
|
||||
[{"src": "../media/test_l.png", "width": 32, "height": 32, "alt": "L"}, "L"],
|
||||
[{"src": "../media/test_m.png", "width": 32, "height": 32, "alt": "M"}, "M"]
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "example_angle",
|
||||
"message0": "angle: %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_angle",
|
||||
"name": "FIELDNAME",
|
||||
"angle": "90",
|
||||
"alt":
|
||||
{
|
||||
"type": "field_label",
|
||||
"text": "NO ANGLE FIELD"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "example_date",
|
||||
"message0": "date: %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_date",
|
||||
"name": "FIELDNAME",
|
||||
"date": "2020-02-20",
|
||||
"alt":
|
||||
{
|
||||
"type": "field_label",
|
||||
"text": "NO DATE FIELD"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "test_number",
|
||||
"message0": "float %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_number",
|
||||
"name": "NUM",
|
||||
"text": "0"
|
||||
}
|
||||
],
|
||||
"colour": 230,
|
||||
"output": "Number",
|
||||
"tooltip": "A number."
|
||||
},
|
||||
{
|
||||
"type": "test_integer",
|
||||
"message0": "integer %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_number",
|
||||
"name": "NUM",
|
||||
"precision": 1,
|
||||
"text": "0"
|
||||
}
|
||||
],
|
||||
"colour": 230,
|
||||
"output": "Number",
|
||||
"tooltip": "An integer."
|
||||
},
|
||||
{
|
||||
"type": "test_number_hundredths",
|
||||
"message0": "$ %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_number",
|
||||
"name": "NUM",
|
||||
"precision": 0.01,
|
||||
"text": "0"
|
||||
}
|
||||
],
|
||||
"colour": 230,
|
||||
"output": "Number",
|
||||
"tooltip": "A dollar amount."
|
||||
},
|
||||
{
|
||||
"type": "test_integer_bounded",
|
||||
"message0": "midi note %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_number",
|
||||
"name": "NOTE",
|
||||
"precision": 1,
|
||||
"min": 1,
|
||||
"max": 127,
|
||||
"text": "0"
|
||||
}
|
||||
],
|
||||
"colour": 230,
|
||||
"output": "Note",
|
||||
"tooltip": "A midi note."
|
||||
},
|
||||
{
|
||||
"type": "image_datauri",
|
||||
"message0": "Image data: URI %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAABHZJREFUaAXtmEuPDFEUx8cwJIx4jQjxSGYt4pWQiGSIz4A1O2FtLyx8B4+MxIKEtQkRsZBIEF/AAgki3gzjNfx/Xfc/rkpVd1dXdU13OMm/z73ndc+5r6rqgYHu01wNAfqa5kTZx+1I3PtNJ35Aqe4P6VrW+9mnEl6o/g/hu0Ab6koxg0nsjn+dVF6c+Yr8SZgUaGeRfR0ry6alzEFaGuYY/AryafFODjQ++EKOlfRq+nXSxzTeY2FHGHcocM/uIvXZWoA2ZJ1td0pGjKMoRY6d9Nr8ndemXdrMyayVYr1wQ9gn3BVIhNklNluKg06fNslTFDacG4q4LgwLxIIcO+nV+HtOY5HoF2FbgXG3y3ZKwPdsAb/KTeOZIxESOhRG2SB+SrgvfBDeC/cEZKwgdFjA5wydQHFMy2rh8WWxOYx4UJybiiTBR+Fzqu/nin2kHohj0a+dmEWfNYpwAefV3iSMCiMC5+GSYD0PSgjfWVkJDmoaJLRO8EocUXulMC68EW4KpuNqUAy2+EDpePRnjdj/JMhKUASH37N/S+0FgrePV+akZLWTl3+jRt4j7BbGhCUC9EAgcbbThdC+KL5aMA2Fxi5xbLkMoKXCmEBMYjMG5DGTXgW/XuqtiuVZNr8S4nM7cbBHBbYTehcxqDZJOTGv2DvJoKuC45lvaWiSbRea+cyHNN8i0UwHgyfilwUS+SYsFkiCmSYWD7tXwkOB5J8H7uRcCL48EPEDTMYqgYngneyl8FSAPHbSq+DXSWSFYmuwIhzg4WDgSYr93GY7kjQ++OaR7fP0M3IPNiNo0mBWCcxMm+izCtbBHRM5emR5FOvxi21ZibifF6Mh96BNjSIlgX9GfRJJkwen4CLbgrj2Tcds2Y9nt6VxQYOOkyo4TsO86IrkjRGvjNvmsQ8yCox1cTu2LdQuW4gT4wYyuZ21rbxKtsHHbcdynEK8TCEM7GS5jp3k8pAB16plQdRYCRLHxjp8JwVilSpG/h0TA08IXwUSAyTFNdwM2Nge32sCsTqmTp09c8zsM4H3KB6EJMcqW5+Oj946X88jklHMGoE3AuvVbJ/KbC1G4crkW4Ptsld4KzimZ1yiGSJJF0chy4Q7Av7xta5uMfKgxbz+WPMOxv9VrMhtwcmTJDqADKIAkgVeNWS8CbAi2M4akciEMCXwusFrB0WQPJy+z0qWDh98S58RxeiYvEXgnJUVIdIJcQqBQ8ib6fCNY+FTmMpsLZIlATiH1MQHFWT+Oun+JcvSOVZk3n5zsH3TTEuKgEjCf4k6pjnyZjqvhmMRrzCVWZF4MJLwwzGW086TW1eqAA/mWXO/b/n/Qnpt6f6vyL++Ir6hzCubj7q3lscz79tC/DVoXlkhVT0QWyXkV/TxYGhueSv/lvq6CuFM8CryQjgdsqJf2VmpfK+GJLOYi+FbvtIiGKwbK+JZNo+LQlb5+WCAbqyIY5rHhXSt3Y3BPOPmXUs+Dlzld7K30iMNwD8q3Ex85lquZv8QhzimdD/W9Xyb5H0z1Zbsb+OT/8HoqhrfAAAAAElFTkSuQmCC",
|
||||
"width": 50,
|
||||
"height": 50,
|
||||
"alt": "*"
|
||||
}
|
||||
],
|
||||
"colour": 160
|
||||
},
|
||||
{
|
||||
"type": "image_small",
|
||||
"message0": "Image too small %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "../media/test_30px.png",
|
||||
"width": 50,
|
||||
"height": 50,
|
||||
"alt": "*"
|
||||
}
|
||||
],
|
||||
"colour": 160
|
||||
},
|
||||
{
|
||||
"type": "image_large",
|
||||
"message0": "Image too large %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "../media/test_200px.png",
|
||||
"width": 50,
|
||||
"height": 50,
|
||||
"alt": "*"
|
||||
}
|
||||
],
|
||||
"colour": 160
|
||||
},
|
||||
{
|
||||
"type": "image_missing",
|
||||
"message0": "Image missing %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "missing.png",
|
||||
"width": 50,
|
||||
"height": 50,
|
||||
"alt": "*"
|
||||
}
|
||||
],
|
||||
"colour": 160
|
||||
},
|
||||
{
|
||||
"type": "test_with_lots_of_network_icons",
|
||||
"message0": "Lots of network icons: %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 %15 %16 %17 %18",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_dummy"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_a.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "A"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_b.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "B"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_c.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "C"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_d.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "D"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_e.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "E"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_f.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "F"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_g.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "G"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_h.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "H"
|
||||
},
|
||||
{
|
||||
"type": "input_dummy"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_a.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "A"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_b.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "B"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_c.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "C"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_d.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "D"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_e.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "E"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_f.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "F"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_g.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "G"
|
||||
},
|
||||
{
|
||||
"type": "field_image",
|
||||
"src": "https://blockly-demo.appspot.com/static/media/test_h.png",
|
||||
"width": 32,
|
||||
"height": 32,
|
||||
"alt": "H"
|
||||
}
|
||||
],
|
||||
"colour": 160
|
||||
},
|
||||
{
|
||||
"type": "styled_event_cap",
|
||||
"message0": "Hat block (event)",
|
||||
"nextStatement": null,
|
||||
"colour": 330,
|
||||
"style": {
|
||||
"hat": "cap"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "block_colour_hex1",
|
||||
"message0": "Block color: Bright purple %1 %2 %3 %4",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "TEXT",
|
||||
"text": "#992aff"
|
||||
},
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "DROPDOWN",
|
||||
"options": [
|
||||
[ "option", "ONE" ],
|
||||
[ "option", "TWO" ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "field_checkbox",
|
||||
"name": "NAME",
|
||||
"checked": true
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NAME"
|
||||
}
|
||||
],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"colour": "#992aff"
|
||||
},
|
||||
{
|
||||
"type": "block_colour_hex2",
|
||||
"message0": "Block color: White %1 %2 %3 %4",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "TEXT",
|
||||
"text": "#fefefe"
|
||||
},
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "DROPDOWN",
|
||||
"options": [
|
||||
[ "option", "ONE" ],
|
||||
[ "option", "TWO" ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "field_checkbox",
|
||||
"name": "NAME",
|
||||
"checked": true
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NAME"
|
||||
}
|
||||
],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"colour": "#fefefe"
|
||||
},
|
||||
{
|
||||
"type": "block_colour_hex3",
|
||||
"message0": "Block color: Black %1 %2 %3 %4",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "TEXT",
|
||||
"text": "#010101"
|
||||
},
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": "DROPDOWN",
|
||||
"options": [
|
||||
[ "option", "ONE" ],
|
||||
[ "option", "TWO" ]
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "field_checkbox",
|
||||
"name": "NAME",
|
||||
"checked": true
|
||||
},
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "NAME"
|
||||
}
|
||||
],
|
||||
"previousStatement": null,
|
||||
"nextStatement": null,
|
||||
"colour": "#010101"
|
||||
},
|
||||
{
|
||||
"type": "block_no_colour",
|
||||
"message0": "Block color: unset"
|
||||
},
|
||||
{
|
||||
"type": "block_colour_hex4",
|
||||
"message0": "Block color: #RRGGBBAA (invalid)",
|
||||
"colour": "#992aff99"
|
||||
},
|
||||
{
|
||||
"type": "block_colour_hex5",
|
||||
"message0": "Block color: #RRGGBB (invalid)",
|
||||
"colour": "#NotHex"
|
||||
},
|
||||
{
|
||||
"type": "emoji_label_robot_face",
|
||||
"message0": "Robot Face: \uD83E\uDD16",
|
||||
"colour": "#AAAAAA"
|
||||
}
|
||||
]); // END JSON EXTRACT (Do not delete this comment.)
|
||||
|
||||
Blockly.Blocks['empty_block_with_mutator'] = {
|
||||
init: function() {
|
||||
this.setMutator(new Blockly.Mutator(['math_number']));
|
||||
}
|
||||
};
|
||||
34
node_modules/node-blockly/blockly/tests/compile/compile.sh
generated
vendored
Executable file
34
node_modules/node-blockly/blockly/tests/compile/compile.sh
generated
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
# Find the Closure Compiler.
|
||||
if [ -f "$(npm root)/google-closure-compiler/compiler.jar" ]; then
|
||||
COMPILER="$(npm root)/google-closure-compiler/compiler.jar"
|
||||
elif [ -f *compiler*.jar ]; then
|
||||
COMPILER="*compiler*.jar"
|
||||
# TODO: Check whether multiple files were found.
|
||||
else
|
||||
echo "ERROR: Closure Compiler not found."
|
||||
echo "Download from this URL, and place jar file in current directory."
|
||||
echo "https://dl.google.com/closure-compiler/compiler-latest.zip"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Using $COMPILER as the compiler.
|
||||
rm main_compressed.js 2> /dev/null
|
||||
echo Compiling Blockly...
|
||||
java -jar $COMPILER --js='main.js' \
|
||||
--js='../../core/**.js' \
|
||||
--js='../../blocks/**.js' \
|
||||
--js='../../generators/**.js' \
|
||||
--js='../../msg/js/**.js' \
|
||||
--js='../../../closure-library/closure/goog/**.js' \
|
||||
--js='../../../closure-library/third_party/closure/goog/**.js' \
|
||||
--generate_exports \
|
||||
--externs ../../externs/svg-externs.js \
|
||||
--compilation_level ADVANCED_OPTIMIZATIONS \
|
||||
--dependency_mode=STRICT --entry_point=Main \
|
||||
--js_output_file main_compressed.js
|
||||
if [ -s main_compressed.js ]; then
|
||||
echo Compilation OK.
|
||||
else
|
||||
echo Compilation FAIL.
|
||||
exit 1
|
||||
fi
|
||||
39
node_modules/node-blockly/blockly/tests/compile/index.html
generated
vendored
Normal file
39
node_modules/node-blockly/blockly/tests/compile/index.html
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blockly: Advanced Compilation Test</title>
|
||||
<script src="main_compressed.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 140%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Blockly: Advanced Compilation Test</h1>
|
||||
|
||||
<p>To run this test manually, download
|
||||
<a href="https://dl.google.com/closure-compiler/compiler-latest.zip">closure-compiler-vxxxxxxxx.jar</a>,
|
||||
place it in this directory, then run compile.js from the command line.</p>
|
||||
|
||||
<p>Measure the size of main_compressed.js (295kb as of October 2017), then reload
|
||||
this page and see if Blockly works.</p>
|
||||
|
||||
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
|
||||
<xml id="toolbox" style="display: none">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<block type="controls_repeat_ext"></block>
|
||||
<block type="math_number"></block>
|
||||
<block type="math_arithmetic"></block>
|
||||
<block type="text"></block>
|
||||
<block type="text_print"></block>
|
||||
</xml>
|
||||
</body>
|
||||
</html>
|
||||
17
node_modules/node-blockly/blockly/tests/compile/main.js
generated
vendored
Normal file
17
node_modules/node-blockly/blockly/tests/compile/main.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
goog.provide('Main');
|
||||
// Messages (in some language)
|
||||
goog.require('Blockly.Msg.en');
|
||||
// Core
|
||||
goog.require('Blockly');
|
||||
// Blocks
|
||||
goog.require('Blockly.Constants.Logic');
|
||||
goog.require('Blockly.Constants.Loops');
|
||||
goog.require('Blockly.Constants.Math');
|
||||
goog.require('Blockly.Constants.Text');
|
||||
|
||||
Main.init = function() {
|
||||
Blockly.inject('blocklyDiv', {
|
||||
'toolbox': document.getElementById('toolbox')
|
||||
});
|
||||
};
|
||||
window.addEventListener('load', Main.init);
|
||||
261
node_modules/node-blockly/blockly/tests/generators/colour.xml
generated
vendored
Normal file
261
node_modules/node-blockly/blockly/tests/generators/colour.xml
generated
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<block type="procedures_defnoreturn" x="260" y="14">
|
||||
<field name="NAME">test colour picker</field>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">static colour</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="630" y="13">
|
||||
<field name="NAME">test rgb</field>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">from rgb</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_rgb" inline="false">
|
||||
<value name="RED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<block type="math_number">
|
||||
<field name="NUM">40</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff6600</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="unittest_main" x="-5" y="49">
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test colour picker"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test blend"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test rgb"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test colour random"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="-7" y="223">
|
||||
<field name="NAME">test colour random</field>
|
||||
<statement name="STACK">
|
||||
<block type="controls_repeat_ext" inline="true">
|
||||
<value name="TIMES">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">item</field>
|
||||
<value name="VALUE">
|
||||
<block type="colour_random"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">test name</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_length" inline="false">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">7</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">test name</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="text_charAt">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="WHERE">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">i</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">7</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">test name</field>
|
||||
</block>
|
||||
</value>
|
||||
<field name="EXPECTED">TRUE</field>
|
||||
<value name="ACTUAL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">NEQ</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="text_indexOf" inline="false">
|
||||
<field name="END">FIRST</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">abcdefABDEF0123456789</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="FIND">
|
||||
<block type="text_charAt">
|
||||
<mutation at="true"></mutation>
|
||||
<field name="WHERE">FROM_START</field>
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="AT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">i</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="520" y="205">
|
||||
<field name="NAME">test blend</field>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">blend</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="colour_blend" inline="false">
|
||||
<value name="COLOUR1">
|
||||
<block type="colour_picker">
|
||||
<field name="COLOUR">#ff0000</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="COLOUR2">
|
||||
<block type="colour_rgb" inline="false">
|
||||
<value name="RED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<block type="math_number">
|
||||
<field name="NUM">40</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="RATIO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0.4</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">#ff2900</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
560
node_modules/node-blockly/blockly/tests/generators/functions.xml
generated
vendored
Normal file
560
node_modules/node-blockly/blockly/tests/generators/functions.xml
generated
vendored
Normal file
@@ -0,0 +1,560 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<!-- Do not include <variables> here to test backward compatibility. -->
|
||||
<block type="unittest_main" x="0" y="1">
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test procedure"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test function"></mutation>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">test recurse</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="recurse">
|
||||
<arg name="n"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">-1-2-1-3-1-2-1-</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="-3" y="249">
|
||||
<field name="NAME">test procedure</field>
|
||||
<statement name="STACK">
|
||||
<block type="procedures_callnoreturn" inline="false">
|
||||
<mutation name="procedure 1">
|
||||
<arg name="proc x"></arg>
|
||||
<arg name="proc y"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ARG1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">procedure with global</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc z</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">proc w</field>
|
||||
<value name="VALUE">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn" inline="false">
|
||||
<mutation name="procedure 2">
|
||||
<arg name="proc x"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">procedure no return</field>
|
||||
</block>
|
||||
</value>
|
||||
<field name="EXPECTED">TRUE</field>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc w</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">proc w</field>
|
||||
<value name="VALUE">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn" inline="false">
|
||||
<mutation name="procedure 2">
|
||||
<arg name="proc x"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">procedure return</field>
|
||||
</block>
|
||||
</value>
|
||||
<field name="EXPECTED">FALSE</field>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc w</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="302" y="277">
|
||||
<mutation>
|
||||
<arg name="proc x"></arg>
|
||||
<arg name="proc y"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">procedure 1</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">proc z</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">DIVIDE</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc y</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="307" y="435">
|
||||
<mutation>
|
||||
<arg name="proc x"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">procedure 2</field>
|
||||
<statement name="STACK">
|
||||
<block type="procedures_ifreturn">
|
||||
<mutation value="0"></mutation>
|
||||
<value name="CONDITION">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">proc x</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">proc w</field>
|
||||
<value name="VALUE">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="-2" y="731">
|
||||
<field name="NAME">test function</field>
|
||||
<statement name="STACK">
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function with arguments</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="function 1">
|
||||
<arg name="func x"></arg>
|
||||
<arg name="func y"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ARG1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">-1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function with side effect</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func z</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">side effect</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">func a</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">unchanged</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">func c</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">global</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function with global</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="function 2">
|
||||
<arg name="func a"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">3global</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function with scope</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">unchanged</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function return</field>
|
||||
</block>
|
||||
</value>
|
||||
<field name="EXPECTED">TRUE</field>
|
||||
<value name="ACTUAL">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="function 3">
|
||||
<arg name="func a"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertvalue" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">function no return</field>
|
||||
</block>
|
||||
</value>
|
||||
<field name="EXPECTED">FALSE</field>
|
||||
<value name="ACTUAL">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="function 3">
|
||||
<arg name="func a"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defreturn" inline="false" x="-3" y="1384">
|
||||
<mutation>
|
||||
<arg name="func x"></arg>
|
||||
<arg name="func y"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">function 1</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">func z</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">side effect</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="RETURN">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">MINUS</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func y</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defreturn" inline="false" x="-1" y="1503">
|
||||
<mutation>
|
||||
<arg name="func a"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">function 2</field>
|
||||
<statement name="STACK">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">func a</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="RETURN">
|
||||
<block type="text_join" inline="false">
|
||||
<mutation items="2"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func c</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defreturn" inline="false" x="0" y="1655">
|
||||
<mutation>
|
||||
<arg name="func a"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">function 3</field>
|
||||
<statement name="STACK">
|
||||
<block type="procedures_ifreturn">
|
||||
<mutation value="1"></mutation>
|
||||
<value name="CONDITION">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">func a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="VALUE">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="RETURN">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="procedures_defreturn" inline="false" x="0" y="1789">
|
||||
<mutation>
|
||||
<arg name="n"></arg>
|
||||
</mutation>
|
||||
<field name="NAME">recurse</field>
|
||||
<statement name="STACK">
|
||||
<block type="controls_if" inline="false">
|
||||
<mutation else="1"></mutation>
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">GT</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">n</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">text</field>
|
||||
<value name="VALUE">
|
||||
<block type="text_join" inline="false">
|
||||
<mutation items="3"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="recurse">
|
||||
<arg name="n"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">MINUS</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">n</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">n</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="procedures_callreturn" inline="false">
|
||||
<mutation name="recurse">
|
||||
<arg name="n"></arg>
|
||||
</mutation>
|
||||
<value name="ARG0">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">MINUS</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">n</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<statement name="ELSE">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">text</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT">-</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</statement>
|
||||
<value name="RETURN">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</xml>
|
||||
377
node_modules/node-blockly/blockly/tests/generators/index.html
generated
vendored
Normal file
377
node_modules/node-blockly/blockly/tests/generators/index.html
generated
vendored
Normal file
@@ -0,0 +1,377 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blockly Generator Tests</title>
|
||||
<script src="../../blockly_uncompressed.js"></script>
|
||||
|
||||
<script src="../../generators/javascript.js"></script>
|
||||
<script src="unittest_javascript.js"></script>
|
||||
<script src="../../generators/javascript/logic.js"></script>
|
||||
<script src="../../generators/javascript/loops.js"></script>
|
||||
<script src="../../generators/javascript/math.js"></script>
|
||||
<script src="../../generators/javascript/text.js"></script>
|
||||
<script src="../../generators/javascript/lists.js"></script>
|
||||
<script src="../../generators/javascript/colour.js"></script>
|
||||
<script src="../../generators/javascript/variables.js"></script>
|
||||
<script src="../../generators/javascript/procedures.js"></script>
|
||||
|
||||
<script src="../../generators/python.js"></script>
|
||||
<script src="unittest_python.js"></script>
|
||||
<script src="../../generators/python/logic.js"></script>
|
||||
<script src="../../generators/python/loops.js"></script>
|
||||
<script src="../../generators/python/math.js"></script>
|
||||
<script src="../../generators/python/text.js"></script>
|
||||
<script src="../../generators/python/lists.js"></script>
|
||||
<script src="../../generators/python/colour.js"></script>
|
||||
<script src="../../generators/python/variables.js"></script>
|
||||
<script src="../../generators/python/procedures.js"></script>
|
||||
|
||||
<script src="../../generators/php.js"></script>
|
||||
<script src="unittest_php.js"></script>
|
||||
<script src="../../generators/php/logic.js"></script>
|
||||
<script src="../../generators/php/loops.js"></script>
|
||||
<script src="../../generators/php/math.js"></script>
|
||||
<script src="../../generators/php/text.js"></script>
|
||||
<script src="../../generators/php/lists.js"></script>
|
||||
<script src="../../generators/php/colour.js"></script>
|
||||
<script src="../../generators/php/variables.js"></script>
|
||||
<script src="../../generators/php/procedures.js"></script>
|
||||
|
||||
<script src="../../generators/lua.js"></script>
|
||||
<script src="unittest_lua.js"></script>
|
||||
<script src="../../generators/lua/logic.js"></script>
|
||||
<script src="../../generators/lua/loops.js"></script>
|
||||
<script src="../../generators/lua/math.js"></script>
|
||||
<script src="../../generators/lua/text.js"></script>
|
||||
<script src="../../generators/lua/lists.js"></script>
|
||||
<script src="../../generators/lua/colour.js"></script>
|
||||
<script src="../../generators/lua/variables.js"></script>
|
||||
<script src="../../generators/lua/procedures.js"></script>
|
||||
|
||||
<script src="../../generators/dart.js"></script>
|
||||
<script src="unittest_dart.js"></script>
|
||||
<script src="../../generators/dart/logic.js"></script>
|
||||
<script src="../../generators/dart/loops.js"></script>
|
||||
<script src="../../generators/dart/math.js"></script>
|
||||
<script src="../../generators/dart/text.js"></script>
|
||||
<script src="../../generators/dart/lists.js"></script>
|
||||
<script src="../../generators/dart/colour.js"></script>
|
||||
<script src="../../generators/dart/variables.js"></script>
|
||||
<script src="../../generators/dart/procedures.js"></script>
|
||||
|
||||
<script src="unittest.js"></script>
|
||||
<script src="../../msg/messages.js"></script>
|
||||
<script src="../../blocks/logic.js"></script>
|
||||
<script src="../../blocks/loops.js"></script>
|
||||
<script src="../../blocks/math.js"></script>
|
||||
<script src="../../blocks/text.js"></script>
|
||||
<script src="../../blocks/lists.js"></script>
|
||||
<script src="../../blocks/colour.js"></script>
|
||||
<script src="../../blocks/variables.js"></script>
|
||||
<script src="../../blocks/procedures.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
var demoWorkspace = null;
|
||||
|
||||
function start() {
|
||||
demoWorkspace = Blockly.inject('blocklyDiv',
|
||||
{grid:
|
||||
{spacing: 25,
|
||||
length: 3,
|
||||
colour: '#ccc',
|
||||
snap: true},
|
||||
media: '../../media/',
|
||||
toolbox: document.getElementById('toolbox'),
|
||||
zoom: {controls: true, wheel: true}
|
||||
});
|
||||
changeIndex();
|
||||
}
|
||||
|
||||
function loadXml() {
|
||||
var dropdown = document.getElementById('testUrl');
|
||||
var url = dropdown.options[dropdown.selectedIndex].value;
|
||||
if (!url) {
|
||||
url = window.prompt('Enter URL of test file.');
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var xmlText = fetchFile(url);
|
||||
if (xmlText !== null) {
|
||||
fromXml(url, xmlText);
|
||||
}
|
||||
}
|
||||
|
||||
function fetchFile(xmlUrl) {
|
||||
try {
|
||||
var xmlHttp = new XMLHttpRequest();
|
||||
xmlHttp.open('GET', xmlUrl, false);
|
||||
xmlHttp.setRequestHeader('Content-Type', 'text/xml');
|
||||
xmlHttp.send('');
|
||||
} catch (e) {
|
||||
// Attempt to diagnose the problem.
|
||||
var msg = 'Error: Unable to load XML data.\n';
|
||||
if (window.location.protocol == 'file:') {
|
||||
msg += 'This may be due to a security restriction preventing\n' +
|
||||
'access when using the file:// protocol.\n' +
|
||||
'Use an http webserver, or a less paranoid browser.\n';
|
||||
}
|
||||
alert(msg + '\n' + e);
|
||||
return null;
|
||||
}
|
||||
return xmlHttp.responseText;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filename The URL (or other name) of the XML, for reporting.
|
||||
* @param {string} xmlText The actual XML text.
|
||||
*/
|
||||
function fromXml(filename, xmlText) {
|
||||
var output = document.getElementById('importExport');
|
||||
output.value = xmlText;
|
||||
output.scrollTop = 0;
|
||||
output.scrollLeft = 0;
|
||||
demoWorkspace.clear();
|
||||
try {
|
||||
var xmlDoc = Blockly.Xml.textToDom(xmlText);
|
||||
Blockly.Xml.domToWorkspace(xmlDoc, demoWorkspace);
|
||||
} catch (e) {
|
||||
var msg = 'Error parsing XML: ' + filename + '\n\n\t' + e;
|
||||
if (e.stack) {
|
||||
msg += '\n\nSee console for stack trace details.'
|
||||
}
|
||||
console.error(e.stack ? e : msg);
|
||||
alert(msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function setOutput(text) {
|
||||
var output = document.getElementById('importExport');
|
||||
output.value = text;
|
||||
output.focus();
|
||||
output.select();
|
||||
}
|
||||
|
||||
function toXml() {
|
||||
var xmlDom = Blockly.Xml.workspaceToDom(demoWorkspace,
|
||||
/* opt_noId */ true);
|
||||
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
|
||||
xmlText = xmlText.replace(/ id="\d+"/g, '');
|
||||
setOutput(xmlText);
|
||||
}
|
||||
|
||||
function toJavaScript() {
|
||||
var code = '\'use strict\';\n\n'
|
||||
code += Blockly.JavaScript.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
}
|
||||
|
||||
function toPython() {
|
||||
var code = Blockly.Python.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
}
|
||||
|
||||
function toPhp() {
|
||||
var code = Blockly.PHP.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
}
|
||||
|
||||
function toLua() {
|
||||
var code = Blockly.Lua.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
}
|
||||
|
||||
function toDart() {
|
||||
var code = Blockly.Dart.workspaceToCode(demoWorkspace);
|
||||
setOutput(code);
|
||||
}
|
||||
|
||||
function changeIndex() {
|
||||
var oneBasedIndex = document.getElementById('indexing').checked;
|
||||
demoWorkspace.options.oneBasedIndex = oneBasedIndex;
|
||||
demoWorkspace.toolbox_.flyout_.workspace_.options.oneBasedIndex = oneBasedIndex;
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
margin: 0 5px;
|
||||
}
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 140%;
|
||||
}
|
||||
#blocklyDiv {
|
||||
float: right;
|
||||
height: 95%;
|
||||
width: 69%;
|
||||
margin-top: 5px;
|
||||
}
|
||||
#importExport {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="start()">
|
||||
|
||||
<div id="blocklyDiv"></div>
|
||||
|
||||
<xml id="toolbox" style="display: none">
|
||||
<category name="Unit test" colour="65">
|
||||
<block type="unittest_main"></block>
|
||||
<block type="unittest_assertequals">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="unittest_assertvalue">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="unittest_fail"></block>
|
||||
<block type="unittest_adjustindex"></block>
|
||||
</category>
|
||||
<category name="Logic" colour="210">
|
||||
<block type="controls_if"></block>
|
||||
<block type="controls_ifelse"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<block type="logic_operation"></block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean"></block>
|
||||
<block type="logic_null"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</category>
|
||||
<category name="Loops" colour="120">
|
||||
<block type="controls_repeat_ext"></block>
|
||||
<block type="controls_whileUntil"></block>
|
||||
<block type="controls_for"></block>
|
||||
<block type="controls_forEach"></block>
|
||||
<block type="controls_flow_statements"></block>
|
||||
</category>
|
||||
<category name="Math" colour="230">
|
||||
<block type="math_number"></block>
|
||||
<block type="math_arithmetic"></block>
|
||||
<block type="math_single"></block>
|
||||
<block type="math_trig"></block>
|
||||
<block type="math_constant"></block>
|
||||
<block type="math_number_property"></block>
|
||||
<block type="math_round"></block>
|
||||
<block type="math_on_list"></block>
|
||||
<block type="math_modulo"></block>
|
||||
<block type="math_constrain"></block>
|
||||
<block type="math_random_int"></block>
|
||||
<block type="math_random_float"></block>
|
||||
</category>
|
||||
<category name="Text" colour="160">
|
||||
<block type="text"></block>
|
||||
<block type="text_join"></block>
|
||||
<block type="text_append"></block>
|
||||
<block type="text_length"></block>
|
||||
<block type="text_isEmpty"></block>
|
||||
<block type="text_indexOf"></block>
|
||||
<block type="text_charAt"></block>
|
||||
<block type="text_getSubstring"></block>
|
||||
<block type="text_changeCase"></block>
|
||||
<block type="text_trim"></block>
|
||||
<block type="text_print"></block>
|
||||
<block type="text_prompt_ext"></block>
|
||||
<block type="text_count"></block>
|
||||
<block type="text_replace"></block>
|
||||
<block type="text_reverse"></block>
|
||||
</category>
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_empty"></block>
|
||||
<block type="lists_create_with"></block>
|
||||
<block type="lists_repeat"></block>
|
||||
<block type="lists_length"></block>
|
||||
<block type="lists_isEmpty"></block>
|
||||
<block type="lists_indexOf"></block>
|
||||
<block type="lists_getIndex"></block>
|
||||
<block type="lists_setIndex"></block>
|
||||
<block type="lists_getSublist"></block>
|
||||
<block type="lists_sort"></block>
|
||||
<block type="lists_split"></block>
|
||||
<block type="lists_reverse"></block>
|
||||
</category>
|
||||
<category name="Colour" colour="20">
|
||||
<block type="colour_picker"></block>
|
||||
<block type="colour_random"></block>
|
||||
<block type="colour_rgb"></block>
|
||||
<block type="colour_blend"></block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
</xml>
|
||||
|
||||
<table height="95%" width="30%"><tr><td valign="top">
|
||||
<h1>Blockly Generator Tests</h1>
|
||||
|
||||
<p><a href="https://developers.google.com/blockly/guides/modify/web/unit-testing">See the docs</a> for details on running the tests.
|
||||
|
||||
<p>
|
||||
<select id="testUrl">
|
||||
<option value="logic.xml">Logic</option>
|
||||
<option value="loops1.xml">Loops 1 (repeat, while, foreach)</option>
|
||||
<option value="loops2.xml">Loops 2 (count)</option>
|
||||
<option value="loops3.xml">Loops 3 (continue, break)</option>
|
||||
<option value="math.xml">Math</option>
|
||||
<option value="text.xml">Text</option>
|
||||
<option value="lists.xml">Lists</option>
|
||||
<option value="colour.xml">Colour</option>
|
||||
<option value="variables.xml">Variables</option>
|
||||
<option value="functions.xml">Functions</option>
|
||||
<option value="">Other...</option>
|
||||
</select>
|
||||
<input type="button" value="Load" onclick="loadXml()">
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input id="indexing" type="checkbox" onchange="changeIndex()" checked>
|
||||
<label for="indexing">Generate with one-based indexing</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Generate:
|
||||
<input type="button" value="XML" onclick="toXml()">
|
||||
<div style="display: inline-block;">
|
||||
<input type="button" value="JavaScript" onclick="toJavaScript()">
|
||||
<br><a target="_blank" href="https://repl.it/languages/javascript">interpreter</a>
|
||||
</div>
|
||||
<div style="display: inline-block;">
|
||||
<input type="button" value="Python" onclick="toPython()">
|
||||
<br><a target="_blank" href="https://repl.it/languages/python">interpreter</a>
|
||||
</div>
|
||||
<div style="display: inline-block;">
|
||||
<input type="button" value="PHP" onclick="toPhp()">
|
||||
<br><a target="_blank" href="https://repl.it/languages/php">interpreter</a>
|
||||
</div>
|
||||
<div style="display: inline-block;">
|
||||
<input type="button" value="Lua" onclick="toLua()">
|
||||
<br><a target="_blank" href="http://rextester.com/l/lua_online_compiler">interpreter</a>
|
||||
</div>
|
||||
<div style="display: inline-block;">
|
||||
<input type="button" value="Dart" onclick="toDart()">
|
||||
<br><a target="_blank" href="https://dartpad.dartlang.org/">interpreter</a>
|
||||
</div>
|
||||
</p>
|
||||
</td></tr><tr><td height="99%">
|
||||
<textarea id="importExport" readonly="readonly" wrap="off"></textarea>
|
||||
</td></tr></table>
|
||||
</body>
|
||||
</html>
|
||||
8284
node_modules/node-blockly/blockly/tests/generators/lists.xml
generated
vendored
Normal file
8284
node_modules/node-blockly/blockly/tests/generators/lists.xml
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1018
node_modules/node-blockly/blockly/tests/generators/logic.xml
generated
vendored
Normal file
1018
node_modules/node-blockly/blockly/tests/generators/logic.xml
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
344
node_modules/node-blockly/blockly/tests/generators/loops1.xml
generated
vendored
Normal file
344
node_modules/node-blockly/blockly/tests/generators/loops1.xml
generated
vendored
Normal file
@@ -0,0 +1,344 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<block type="unittest_main" x="33" y="140">
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test repeat"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test repeat_ext"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test while"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test foreach"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="31" y="296">
|
||||
<mutation></mutation>
|
||||
<field name="NAME">test foreach</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_forEach" inline="false">
|
||||
<field name="VAR">x</field>
|
||||
<value name="LIST">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="3"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="text">
|
||||
<field name="TEXT">b</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="text">
|
||||
<field name="TEXT">c</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">for loop</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="30" y="624">
|
||||
<mutation></mutation>
|
||||
<field name="NAME">test while</field>
|
||||
<statement name="STACK">
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">FALSE</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="unittest_fail">
|
||||
<field name="MESSAGE">while 0</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">UNTIL</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_boolean">
|
||||
<field name="BOOL">TRUE</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="unittest_fail">
|
||||
<field name="MESSAGE">until 0</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">NEQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">while 10</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">UNTIL</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">until 10</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="397" y="448">
|
||||
<mutation></mutation>
|
||||
<field name="NAME">test repeat</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_repeat" inline="true">
|
||||
<field name="TIMES">10</field>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">repeat 10</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="397" y="668">
|
||||
<mutation></mutation>
|
||||
<field name="NAME">test repeat_ext</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_repeat_ext" inline="true">
|
||||
<value name="TIMES">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">repeat 10</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
890
node_modules/node-blockly/blockly/tests/generators/loops2.xml
generated
vendored
Normal file
890
node_modules/node-blockly/blockly/tests/generators/loops2.xml
generated
vendored
Normal file
@@ -0,0 +1,890 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<block type="unittest_main" x="66" y="-2">
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test count"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test count by"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="679" y="-10">
|
||||
<field name="NAME">test count by</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count up ints</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">1357</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count down ints</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">8642</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count with floats</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="5"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD4">
|
||||
<block type="math_number">
|
||||
<field name="NUM">7</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">MINUS</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count up non-trivial ints</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="8"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD4">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD5">
|
||||
<block type="math_number">
|
||||
<field name="NUM">6</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD6">
|
||||
<block type="math_number">
|
||||
<field name="NUM">7</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD7">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count down non-trivial ints</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">6</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0.5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count with floats</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="5"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2.5</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD4">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1.5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="29" y="184">
|
||||
<field name="NAME">test count</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count up</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">12345678</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count down</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">87654321</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count up non-trivial</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">loglist</field>
|
||||
<value name="VALUE">
|
||||
<block type="lists_create_empty"></block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_arithmetic">
|
||||
<field name="OP">ADD</field>
|
||||
<value name="A">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="lists_setIndex">
|
||||
<mutation at="false"></mutation>
|
||||
<field name="MODE">INSERT</field>
|
||||
<field name="WHERE">LAST</field>
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count down non-trivial</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">loglist</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="math_number">
|
||||
<field name="NUM">4</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="math_number">
|
||||
<field name="NUM">3</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="math_number">
|
||||
<field name="NUM">2</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
734
node_modules/node-blockly/blockly/tests/generators/loops3.xml
generated
vendored
Normal file
734
node_modules/node-blockly/blockly/tests/generators/loops3.xml
generated
vendored
Normal file
@@ -0,0 +1,734 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<block type="unittest_main" x="19" y="106">
|
||||
<statement name="DO">
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test break"></mutation>
|
||||
<next>
|
||||
<block type="procedures_callnoreturn">
|
||||
<mutation name="test continue"></mutation>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="13" y="300">
|
||||
<field name="NAME">test continue</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">NEQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">CONTINUE</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">while continue</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">1234678</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">UNTIL</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">CONTINUE</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">until continue</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">1234678</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">CONTINUE</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count continue</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">1234678</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_forEach" inline="false">
|
||||
<field name="VAR">x</field>
|
||||
<value name="LIST">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="text">
|
||||
<field name="TEXT">b</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="text">
|
||||
<field name="TEXT">c</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="text">
|
||||
<field name="TEXT">d</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="text">
|
||||
<field name="TEXT">c</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">CONTINUE</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">for continue</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">abd</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="procedures_defnoreturn" x="600" y="300">
|
||||
<field name="NAME">test break</field>
|
||||
<statement name="STACK">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">WHILE</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">NEQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">BREAK</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">while break</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_whileUntil" inline="false">
|
||||
<field name="MODE">UNTIL</field>
|
||||
<value name="BOOL">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">BREAK</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="math_change" inline="false">
|
||||
<field name="VAR">count</field>
|
||||
<value name="DELTA">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">until break</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">count</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_for">
|
||||
<field name="VAR">x</field>
|
||||
<value name="FROM">
|
||||
<block type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<block type="math_number">
|
||||
<field name="NUM">8</field>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">BREAK</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">count break</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">1234</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="VALUE">
|
||||
<block type="text">
|
||||
<field name="TEXT"></field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="controls_forEach" inline="false">
|
||||
<field name="VAR">x</field>
|
||||
<value name="LIST">
|
||||
<block type="lists_create_with" inline="false">
|
||||
<mutation items="4"></mutation>
|
||||
<value name="ADD0">
|
||||
<block type="text">
|
||||
<field name="TEXT">a</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD1">
|
||||
<block type="text">
|
||||
<field name="TEXT">b</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD2">
|
||||
<block type="text">
|
||||
<field name="TEXT">c</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ADD3">
|
||||
<block type="text">
|
||||
<field name="TEXT">d</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO">
|
||||
<block type="controls_if" inline="false">
|
||||
<value name="IF0">
|
||||
<block type="logic_compare">
|
||||
<field name="OP">EQ</field>
|
||||
<value name="A">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="B">
|
||||
<block type="text">
|
||||
<field name="TEXT">c</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</value>
|
||||
<statement name="DO0">
|
||||
<block type="controls_flow_statements">
|
||||
<field name="FLOW">BREAK</field>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="text_append" inline="false">
|
||||
<field name="VAR">log</field>
|
||||
<value name="TEXT">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">x</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">for break</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">log</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="text">
|
||||
<field name="TEXT">ab</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
</xml>
|
||||
1884
node_modules/node-blockly/blockly/tests/generators/math.xml
generated
vendored
Normal file
1884
node_modules/node-blockly/blockly/tests/generators/math.xml
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4650
node_modules/node-blockly/blockly/tests/generators/text.xml
generated
vendored
Normal file
4650
node_modules/node-blockly/blockly/tests/generators/text.xml
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
117
node_modules/node-blockly/blockly/tests/generators/unittest.js
generated
vendored
Normal file
117
node_modules/node-blockly/blockly/tests/generators/unittest.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Unit test blocks for Blockly.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Blocks['unittest_main'] = {
|
||||
// Container for unit tests.
|
||||
init: function() {
|
||||
this.setColour(65);
|
||||
this.appendDummyInput()
|
||||
.appendField('run tests');
|
||||
this.appendStatementInput('DO');
|
||||
this.setTooltip('Executes the enclosed unit tests,\n' +
|
||||
'then prints a summary.');
|
||||
},
|
||||
getDeveloperVars: function() {
|
||||
return ['unittestResults'];
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['unittest_assertequals'] = {
|
||||
// Asserts that a value equals another value.
|
||||
init: function() {
|
||||
this.setColour(65);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendValueInput('MESSAGE')
|
||||
.appendField('name')
|
||||
.setCheck('String');
|
||||
this.appendValueInput('ACTUAL')
|
||||
.appendField('actual');
|
||||
this.appendValueInput('EXPECTED')
|
||||
.appendField('expected');
|
||||
this.setTooltip('Tests that "actual == expected".');
|
||||
},
|
||||
getDeveloperVars: function() {
|
||||
return ['unittestResults'];
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['unittest_assertvalue'] = {
|
||||
// Asserts that a value is true, false, or null.
|
||||
init: function() {
|
||||
this.setColour(65);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendValueInput('MESSAGE', 'test name')
|
||||
.appendField('name')
|
||||
.setCheck('String');
|
||||
this.appendValueInput('ACTUAL')
|
||||
.appendField('assert')
|
||||
.appendField(new Blockly.FieldDropdown(
|
||||
[['true', 'TRUE'], ['false', 'FALSE'], ['null', 'NULL']]), 'EXPECTED');
|
||||
this.setTooltip('Tests that the value is true, false, or null.');
|
||||
},
|
||||
getDeveloperVars: function() {
|
||||
return ['unittestResults'];
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['unittest_fail'] = {
|
||||
// Always assert an error.
|
||||
init: function() {
|
||||
this.setColour(65);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldTextInput('test name'), 'MESSAGE')
|
||||
.appendField('fail');
|
||||
this.setTooltip('Records an error.');
|
||||
},
|
||||
getDeveloperVars: function() {
|
||||
return ['unittestResults'];
|
||||
}
|
||||
};
|
||||
|
||||
Blockly.Blocks['unittest_adjustindex'] = {
|
||||
// Adjusts the indexing based on current setting.
|
||||
init: function() {
|
||||
this.jsonInit({
|
||||
"message0": "adjusted %1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "INDEX",
|
||||
"check": "Number"
|
||||
}
|
||||
],
|
||||
"inputsInline": true,
|
||||
"output": "Number",
|
||||
"colour": 65,
|
||||
"tooltip": "Adjusts the value based on whether generated code is using " +
|
||||
"zero or one based indexing."
|
||||
});
|
||||
}
|
||||
};
|
||||
173
node_modules/node-blockly/blockly/tests/generators/unittest_dart.js
generated
vendored
Normal file
173
node_modules/node-blockly/blockly/tests/generators/unittest_dart.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2014 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Generating Dart for unit test blocks.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Dart['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'String ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' // Create test report.',
|
||||
' List report = [];',
|
||||
' StringBuffer summary = new StringBuffer();',
|
||||
' int fails = 0;',
|
||||
' for (int x = 0; x < ' + resultsVar + '.length; x++) {',
|
||||
' if (' + resultsVar + '[x][0]) {',
|
||||
' summary.write(".");',
|
||||
' } else {',
|
||||
' summary.write("F");',
|
||||
' fails++;',
|
||||
' report.add("");',
|
||||
' report.add("FAIL: ${' + resultsVar + '[x][2]}");',
|
||||
' report.add(' + resultsVar + '[x][1]);',
|
||||
' }',
|
||||
' }',
|
||||
' report.insert(0, summary.toString());',
|
||||
' report.add("");',
|
||||
' report.add("Ran ${' + resultsVar + '.length} tests.");',
|
||||
' report.add("");',
|
||||
' if (fails != 0) {',
|
||||
' report.add("FAILED (failures=$fails)");',
|
||||
' } else {',
|
||||
' report.add("OK");',
|
||||
' }',
|
||||
' return report.join("\\n");',
|
||||
'}']);
|
||||
// Setup global to hold test results.
|
||||
var code = resultsVar + ' = [];\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Dart.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report to the console (that's where errors will go anyway).
|
||||
code += 'print(' + functionName + '());\n';
|
||||
// Destroy results.
|
||||
code += resultsVar + ' = null;\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
'unittest_assertequals',
|
||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(dynamic actual, dynamic expected, String message) {',
|
||||
' // Asserts that a value equals another value.',
|
||||
' if (' + resultsVar + ' == null) {',
|
||||
' throw "Orphaned assert: ${message}";',
|
||||
' }',
|
||||
' bool equals(a, b) {',
|
||||
' if (a == b) {',
|
||||
' return true;',
|
||||
' } else if (a is List && b is List) {',
|
||||
' if (a.length != b.length) {',
|
||||
' return false;',
|
||||
' }',
|
||||
' for (num i = 0; i < a.length; i++) {',
|
||||
' if (!equals(a[i], b[i])) {',
|
||||
' return false;',
|
||||
' }',
|
||||
' }',
|
||||
' return true;',
|
||||
' }',
|
||||
' return false;',
|
||||
' }',
|
||||
' if (equals(actual, expected)) {',
|
||||
' ' + resultsVar + '.add([true, "OK", message]);',
|
||||
' } else {',
|
||||
' ' + resultsVar + '.add([false, ' +
|
||||
'"Expected: $expected\\nActual: $actual", message]);',
|
||||
' }',
|
||||
'}']);
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Dart.ORDER_NONE) || '';
|
||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
var expected = Blockly.Dart.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Dart.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Dart.ORDER_NONE) || '';
|
||||
var actual = Blockly.Dart.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Dart.ORDER_NONE) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
} else if (expected == 'FALSE') {
|
||||
expected = 'false';
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.Dart['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Dart.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Dart.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Dart.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'void ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(String message) {',
|
||||
' // Always assert an error.',
|
||||
' if (' + resultsVar + ' == null) {',
|
||||
' throw "Orphaned assert fail: ${message}";',
|
||||
' }',
|
||||
' ' + resultsVar + '.add([false, "Fail.", message]);',
|
||||
'}']);
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.Dart['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Dart.valueToCode(block, 'INDEX',
|
||||
Blockly.Dart.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Dart.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.Dart.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.Dart.ORDER_ADDITIVE];
|
||||
};
|
||||
177
node_modules/node-blockly/blockly/tests/generators/unittest_javascript.js
generated
vendored
Normal file
177
node_modules/node-blockly/blockly/tests/generators/unittest_javascript.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Generating JavaScript for unit test blocks.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.JavaScript['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' // Create test report.',
|
||||
' var report = [];',
|
||||
' var summary = [];',
|
||||
' var fails = 0;',
|
||||
' for (var i = 0; i < ' + resultsVar + '.length; i++) {',
|
||||
' if (' + resultsVar + '[i][0]) {',
|
||||
' summary.push(".");',
|
||||
' } else {',
|
||||
' summary.push("F");',
|
||||
' fails++;',
|
||||
' report.push("");',
|
||||
' report.push("FAIL: " + ' + resultsVar + '[i][2]);',
|
||||
' report.push(' + resultsVar + '[i][1]);',
|
||||
' }',
|
||||
' }',
|
||||
' report.unshift(summary.join(""));',
|
||||
' report.push("");',
|
||||
' report.push("Number of tests run: " + ' + resultsVar +
|
||||
'.length);',
|
||||
' report.push("");',
|
||||
' if (fails) {',
|
||||
' report.push("FAILED (failures=" + fails + ")");',
|
||||
' } else {',
|
||||
' report.push("OK");',
|
||||
' }',
|
||||
' return report.join("\\n");',
|
||||
'}']);
|
||||
// Setup global to hold test results.
|
||||
var code = resultsVar + ' = [];\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.JavaScript.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Send the report to the console (that's where errors will go anyway).
|
||||
code += 'console.log(' + functionName + '());\n';
|
||||
// Destroy results.
|
||||
code += resultsVar + ' = null;\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
'assertEquals',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message) {',
|
||||
' // Asserts that a value equals another value.',
|
||||
' if (!' + resultsVar + ') {',
|
||||
' throw "Orphaned assert: " + message;',
|
||||
' }',
|
||||
' function equals(a, b) {',
|
||||
' if (a === b) {',
|
||||
' return true;',
|
||||
' } else if ((typeof a == "number") && (typeof b == "number") &&',
|
||||
' (a.toPrecision(15) == b.toPrecision(15))) {',
|
||||
' return true;',
|
||||
' } else if (a instanceof Array && b instanceof Array) {',
|
||||
' if (a.length != b.length) {',
|
||||
' return false;',
|
||||
' }',
|
||||
' for (var i = 0; i < a.length; i++) {',
|
||||
' if (!equals(a[i], b[i])) {',
|
||||
' return false;',
|
||||
' }',
|
||||
' }',
|
||||
' return true;',
|
||||
' }',
|
||||
' return false;',
|
||||
' }',
|
||||
' if (equals(actual, expected)) {',
|
||||
' ' + resultsVar + '.push([true, "OK", message]);',
|
||||
' } else {',
|
||||
' ' + resultsVar + '.push([false, ' +
|
||||
'"Expected: " + expected + "\\nActual: " + actual, message]);',
|
||||
' }',
|
||||
'}']);
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
||||
Blockly.JavaScript.ORDER_NONE) || '';
|
||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
||||
Blockly.JavaScript.ORDER_COMMA) || 'null';
|
||||
var expected = Blockly.JavaScript.valueToCode(block, 'EXPECTED',
|
||||
Blockly.JavaScript.ORDER_COMMA) || 'null';
|
||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.JavaScript.valueToCode(block, 'MESSAGE',
|
||||
Blockly.JavaScript.ORDER_NONE) || '';
|
||||
var actual = Blockly.JavaScript.valueToCode(block, 'ACTUAL',
|
||||
Blockly.JavaScript.ORDER_COMMA) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
} else if (expected == 'FALSE') {
|
||||
expected = 'false';
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.JavaScript['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.JavaScript.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.JavaScript.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.JavaScript.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'function ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(message) {',
|
||||
' // Always assert an error.',
|
||||
' if (!' + resultsVar + ') {',
|
||||
' throw "Orphaned assert fail: " + message;',
|
||||
' }',
|
||||
' ' + resultsVar + '.push([false, "Fail.", message]);',
|
||||
'}']);
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.JavaScript['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.JavaScript.valueToCode(block, 'INDEX',
|
||||
Blockly.JavaScript.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.JavaScript.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.JavaScript.ORDER_ADDITION];
|
||||
};
|
||||
175
node_modules/node-blockly/blockly/tests/generators/unittest_lua.js
generated
vendored
Normal file
175
node_modules/node-blockly/blockly/tests/generators/unittest_lua.js
generated
vendored
Normal file
@@ -0,0 +1,175 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2016 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Generating Lua for unit test blocks.
|
||||
* @author rodrigoq@google.com (Rodrigo Queiro)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Lua['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
'unittest_report',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '()',
|
||||
' -- Create test report.',
|
||||
' local report = {}',
|
||||
' local summary = {}',
|
||||
' local fails = 0',
|
||||
' for _, v in pairs(' + resultsVar + ') do',
|
||||
' if v["success"] then',
|
||||
' table.insert(summary, ".")',
|
||||
' else',
|
||||
' table.insert(summary, "F")',
|
||||
' fails = fails + 1',
|
||||
' table.insert(report, "FAIL: " .. v["title"])',
|
||||
' table.insert(report, v["log"])',
|
||||
' end',
|
||||
' end',
|
||||
' table.insert(report, 1, table.concat(summary))',
|
||||
' table.insert(report, "")',
|
||||
' table.insert(report, "Number of tests run: " .. #' + resultsVar + ')',
|
||||
' table.insert(report, "")',
|
||||
' if fails > 0 then',
|
||||
' table.insert(report, "FAILED (failures=" .. fails .. ")")',
|
||||
' else',
|
||||
' table.insert(report, "OK")',
|
||||
' end',
|
||||
' return table.concat(report, "\\n")',
|
||||
'end']);
|
||||
// Setup global to hold test results.
|
||||
var code = resultsVar + ' = {}\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Lua.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report.
|
||||
code += 'print(' + functionName + '())\n';
|
||||
// Destroy results.
|
||||
code += resultsVar + ' = nil\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
'assertEquals',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message)',
|
||||
' -- Asserts that a value equals another value.',
|
||||
' assert(' + resultsVar + ' ~= nil, ' +
|
||||
'"Orphaned assert equals: " .. message)',
|
||||
' if type(actual) == "table" and type(expected) == "table" then',
|
||||
' local lists_match = #actual == #expected',
|
||||
' if lists_match then',
|
||||
' for i, v1 in ipairs(actual) do',
|
||||
' local v2 = expected[i]',
|
||||
' if type(v1) == "number" and type(v2) == "number" then',
|
||||
' if math.abs(v1 - v2) > 1e-9 then',
|
||||
' lists_match = false',
|
||||
' end',
|
||||
' elseif v1 ~= v2 then',
|
||||
' lists_match = false',
|
||||
' end',
|
||||
' end',
|
||||
' end',
|
||||
' if lists_match then',
|
||||
' table.insert(' + resultsVar +
|
||||
', {success=true, log="OK", title=message})',
|
||||
' return',
|
||||
' else',
|
||||
' -- produce the non-matching strings for a human-readable error',
|
||||
' expected = "{" .. table.concat(expected, ", ") .. "}"',
|
||||
' actual = "{" .. table.concat(actual, ", ") .. "}"',
|
||||
' end',
|
||||
' end',
|
||||
' if actual == expected or (type(actual) == "number" and ' +
|
||||
'type(expected) == "number" and math.abs(actual - expected) < ' +
|
||||
'1e-9) then ',
|
||||
' table.insert(' + resultsVar +
|
||||
', {success=true, log="OK", title=message})',
|
||||
' else',
|
||||
' table.insert(' + resultsVar + ', {success=false, ' +
|
||||
'log=string.format("Expected: %s\\nActual: %s"' +
|
||||
', tostring(expected), tostring(actual)), title=message})',
|
||||
' end',
|
||||
'end']);
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Lua.ORDER_NONE) || '';
|
||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
var expected = Blockly.Lua.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
return Blockly.Lua['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Lua.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Lua.ORDER_NONE) || '';
|
||||
var actual = Blockly.Lua.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Lua.ORDER_NONE) || 'nil';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
} else if (expected == 'FALSE') {
|
||||
expected = 'false';
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'nil';
|
||||
}
|
||||
return Blockly.Lua.unittest_main.defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Lua.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Lua.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Lua.provideFunction_(
|
||||
'unittest_fail',
|
||||
['function ' + Blockly.Lua.FUNCTION_NAME_PLACEHOLDER_ + '(message)',
|
||||
' -- Always assert an error.',
|
||||
' assert(' + resultsVar +
|
||||
' ~= nil, "Orphaned assert fail: " .. message)',
|
||||
' table.insert(' + resultsVar +
|
||||
', {success=false, log="Fail.", title=message})',
|
||||
'end']);
|
||||
return functionName + '(' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Lua['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Lua.valueToCode(block, 'INDEX',
|
||||
Blockly.Lua.ORDER_ADDITIVE) || '0';
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Lua.ORDER_ATOMIC];
|
||||
}
|
||||
// If the index is dynamic, adjust it in code.
|
||||
return [index + ' + 1', Blockly.Lua.ORDER_ATOMIC];
|
||||
};
|
||||
164
node_modules/node-blockly/blockly/tests/generators/unittest_php.js
generated
vendored
Normal file
164
node_modules/node-blockly/blockly/tests/generators/unittest_php.js
generated
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2015 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Generating PHP for unit test blocks.
|
||||
* @author daarond@gmail.com (Daaron Dwyer)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.PHP['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
'unittest_report',
|
||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ + '() {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Create test report.',
|
||||
' $report = array();',
|
||||
' $summary = array();',
|
||||
' $fails = 0;',
|
||||
' for ($x = 0; $x < count(' + resultsVar + '); $x++) {',
|
||||
' if (' + resultsVar + '[$x][0]) {',
|
||||
' array_push($summary, ".");',
|
||||
' } else {',
|
||||
' array_push($summary, "F");',
|
||||
' $fails++;',
|
||||
' array_push($report, "");',
|
||||
' array_push($report, "FAIL: " . ' + resultsVar + '[$x][2]);',
|
||||
' array_push($report, ' + resultsVar + '[$x][1]);',
|
||||
' }',
|
||||
' }',
|
||||
' array_unshift($report, implode("", $summary));',
|
||||
' array_push($report, "");',
|
||||
' array_push($report, "Number of tests run: " . count(' + resultsVar + '));',
|
||||
' array_push($report, "");',
|
||||
' if ($fails) {',
|
||||
' array_push($report, "FAILED (failures=" . $fails + ")");',
|
||||
' } else {',
|
||||
' array_push($report, "OK");',
|
||||
' }',
|
||||
' return implode("\\n", $report);',
|
||||
'}']);
|
||||
// Setup global to hold test results.
|
||||
var code = resultsVar + ' = array();\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.PHP.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Send the report to the console (that's where errors will go anyway).
|
||||
code += 'print(' + functionName + '());\n';
|
||||
// Destroy results.
|
||||
code += resultsVar + ' = null;\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_main'].defineAssert_ = function(block) {
|
||||
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
'assertEquals',
|
||||
['function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'($actual, $expected, $message) {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Asserts that a value equals another value.',
|
||||
' if (!is_array(' + resultsVar + ')) {',
|
||||
' throw new Exception("Orphaned assert: " . $message);',
|
||||
' }',
|
||||
' if ($actual == $expected) {',
|
||||
' array_push(' + resultsVar + ', [true, "OK", $message]);',
|
||||
' } else {',
|
||||
' $expected = is_array($expected) ? implode(" ", $expected) : ' +
|
||||
'$expected;',
|
||||
' $actual = is_array($actual) ? implode(" ", $actual) : ' +
|
||||
'$actual;',
|
||||
' array_push(' + resultsVar + ', [false, ' +
|
||||
'"Expected: " . $expected . "\\nActual: " . $actual, $message]);',
|
||||
' }',
|
||||
'}']);
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
||||
Blockly.PHP.ORDER_NONE) || '';
|
||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
||||
Blockly.PHP.ORDER_COMMA) || 'null';
|
||||
var expected = Blockly.PHP.valueToCode(block, 'EXPECTED',
|
||||
Blockly.PHP.ORDER_COMMA) || 'null';
|
||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.PHP.valueToCode(block, 'MESSAGE',
|
||||
Blockly.PHP.ORDER_NONE) || '';
|
||||
var actual = Blockly.PHP.valueToCode(block, 'ACTUAL',
|
||||
Blockly.PHP.ORDER_COMMA) || 'null';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'true';
|
||||
} else if (expected == 'FALSE') {
|
||||
expected = 'false';
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'null';
|
||||
}
|
||||
return Blockly.PHP['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.PHP.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.PHP.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.PHP.provideFunction_(
|
||||
'unittest_fail',
|
||||
[ 'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'($message) {',
|
||||
' global ' + resultsVar + ';',
|
||||
' // Always assert an error.',
|
||||
' if (!' + resultsVar + ') {',
|
||||
' throw new Exception("Orphaned assert fail: " . $message);',
|
||||
' }',
|
||||
' array_push(' + resultsVar + ', [false, "Fail.", $message]);',
|
||||
'}']);
|
||||
return functionName + '(' + message + ');\n';
|
||||
};
|
||||
|
||||
Blockly.PHP['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.PHP.valueToCode(block, 'INDEX',
|
||||
Blockly.PHP.ORDER_ADDITION) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.PHP.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.PHP.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.PHP.ORDER_ADDITION];
|
||||
};
|
||||
148
node_modules/node-blockly/blockly/tests/generators/unittest_python.js
generated
vendored
Normal file
148
node_modules/node-blockly/blockly/tests/generators/unittest_python.js
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Language
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Generating Python for unit test blocks.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
Blockly.Python['unittest_main'] = function(block) {
|
||||
// Container for unit tests.
|
||||
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
'unittest_report',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '():',
|
||||
' # Create test report.',
|
||||
' report = []',
|
||||
' summary = []',
|
||||
' fails = 0',
|
||||
' for (success, log, message) in ' + resultsVar + ':',
|
||||
' if success:',
|
||||
' summary.append(".")',
|
||||
' else:',
|
||||
' summary.append("F")',
|
||||
' fails += 1',
|
||||
' report.append("")',
|
||||
' report.append("FAIL: " + message)',
|
||||
' report.append(log)',
|
||||
' report.insert(0, "".join(summary))',
|
||||
' report.append("")',
|
||||
' report.append("Number of tests run: %d" % len(' + resultsVar + '))',
|
||||
' report.append("")',
|
||||
' if fails:',
|
||||
' report.append("FAILED (failures=%d)" % fails)',
|
||||
' else:',
|
||||
' report.append("OK")',
|
||||
' return "\\n".join(report)']);
|
||||
|
||||
// Setup global to hold test results.
|
||||
var code = resultsVar + ' = []\n';
|
||||
// Run tests (unindented).
|
||||
code += Blockly.Python.statementToCode(block, 'DO')
|
||||
.replace(/^ /, '').replace(/\n /g, '\n');
|
||||
// Print the report.
|
||||
code += 'print(' + functionName + '())\n';
|
||||
// Destroy results.
|
||||
code += resultsVar + ' = None\n';
|
||||
return code;
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_main'].defineAssert_ = function() {
|
||||
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
'assertEquals',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(actual, expected, message):',
|
||||
' # Asserts that a value equals another value.',
|
||||
' if ' + resultsVar + ' == None:',
|
||||
' raise Exception("Orphaned assert equals: " + message)',
|
||||
' if actual == expected:',
|
||||
' ' + resultsVar + '.append((True, "OK", message))',
|
||||
' else:',
|
||||
' ' + resultsVar + '.append((False, ' +
|
||||
'"Expected: %s\\nActual: %s" % (expected, actual), message))']);
|
||||
return functionName;
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_assertequals'] = function(block) {
|
||||
// Asserts that a value equals another value.
|
||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Python.ORDER_NONE) || '';
|
||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
var expected = Blockly.Python.valueToCode(block, 'EXPECTED',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_assertvalue'] = function(block) {
|
||||
// Asserts that a value is true, false, or null.
|
||||
var message = Blockly.Python.valueToCode(block, 'MESSAGE',
|
||||
Blockly.Python.ORDER_NONE) || '';
|
||||
var actual = Blockly.Python.valueToCode(block, 'ACTUAL',
|
||||
Blockly.Python.ORDER_NONE) || 'None';
|
||||
var expected = block.getFieldValue('EXPECTED');
|
||||
if (expected == 'TRUE') {
|
||||
expected = 'True';
|
||||
} else if (expected == 'FALSE') {
|
||||
expected = 'False';
|
||||
} else if (expected == 'NULL') {
|
||||
expected = 'None';
|
||||
}
|
||||
return Blockly.Python['unittest_main'].defineAssert_() +
|
||||
'(' + actual + ', ' + expected + ', ' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_fail'] = function(block) {
|
||||
// Always assert an error.
|
||||
var resultsVar = Blockly.Python.variableDB_.getName('unittestResults',
|
||||
Blockly.Names.DEVELOPER_VARIABLE_TYPE);
|
||||
var message = Blockly.Python.quote_(block.getFieldValue('MESSAGE'));
|
||||
var functionName = Blockly.Python.provideFunction_(
|
||||
'fail',
|
||||
['def ' + Blockly.Python.FUNCTION_NAME_PLACEHOLDER_ + '(message):',
|
||||
' # Always assert an error.',
|
||||
' if ' + resultsVar + ' == None:',
|
||||
' raise Exception("Orphaned assert equals: " + message)',
|
||||
' ' + resultsVar + '.append((False, "Fail.", message))']);
|
||||
return functionName + '(' + message + ')\n';
|
||||
};
|
||||
|
||||
Blockly.Python['unittest_adjustindex'] = function(block) {
|
||||
var index = Blockly.Python.valueToCode(block, 'INDEX',
|
||||
Blockly.Python.ORDER_ADDITIVE) || '0';
|
||||
// Adjust index if using one-based indexing.
|
||||
if (block.workspace.options.oneBasedIndex) {
|
||||
if (Blockly.isNumber(index)) {
|
||||
// If the index is a naked number, adjust it right now.
|
||||
return [parseFloat(index) + 1, Blockly.Python.ORDER_ATOMIC];
|
||||
} else {
|
||||
// If the index is dynamic, adjust it in code.
|
||||
index = index + ' + 1';
|
||||
}
|
||||
} else if (Blockly.isNumber(index)) {
|
||||
return [index, Blockly.Python.ORDER_ATOMIC];
|
||||
}
|
||||
return [index, Blockly.Python.ORDER_ADDITIVE];
|
||||
};
|
||||
67
node_modules/node-blockly/blockly/tests/generators/variables.xml
generated
vendored
Normal file
67
node_modules/node-blockly/blockly/tests/generators/variables.xml
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
<xml xmlns="http://www.w3.org/1999/xhtml">
|
||||
<!-- Do not include <variables> here to test backward compatibility. -->
|
||||
<block type="unittest_main" x="0" y="0">
|
||||
<statement name="DO">
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">item</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">123</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">variable</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">item</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">123</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="variables_set" inline="false">
|
||||
<field name="VAR">if</field>
|
||||
<value name="VALUE">
|
||||
<block type="math_number">
|
||||
<field name="NUM">123</field>
|
||||
</block>
|
||||
</value>
|
||||
<next>
|
||||
<block type="unittest_assertequals" inline="false">
|
||||
<value name="MESSAGE">
|
||||
<block type="text">
|
||||
<field name="TEXT">reserved variable</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="ACTUAL">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">if</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="EXPECTED">
|
||||
<block type="math_number">
|
||||
<field name="NUM">123</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</next>
|
||||
</block>
|
||||
</statement>
|
||||
</block>
|
||||
<block type="variables_get" x="300" y="100">
|
||||
<field name="VAR">naked</field>
|
||||
<comment pinned="true" h="80" w="160">Intentionally non-connected variable.</comment>
|
||||
</block>
|
||||
</xml>
|
||||
307
node_modules/node-blockly/blockly/tests/jsunit/connection_db_test.js
generated
vendored
Normal file
307
node_modules/node-blockly/blockly/tests/jsunit/connection_db_test.js
generated
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2015 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function verify_DB_(msg, expected, db) {
|
||||
var equal = (expected.length == db.length);
|
||||
if (equal) {
|
||||
for (var i = 0; i < expected.length; i++) {
|
||||
if (expected[i] != db[i]) {
|
||||
equal = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (equal) {
|
||||
assertTrue(msg, true);
|
||||
} else {
|
||||
assertEquals(msg, expected, db);
|
||||
}
|
||||
}
|
||||
|
||||
function test_DB_addConnection() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
var o2 = {y_: 2, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o2);
|
||||
verify_DB_('Adding connection #2', [o2], db);
|
||||
|
||||
var o4 = {y_: 4, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o4);
|
||||
verify_DB_('Adding connection #4', [o2, o4], db);
|
||||
|
||||
var o1 = {y_: 1, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o1);
|
||||
verify_DB_('Adding connection #1', [o1, o2, o4], db);
|
||||
|
||||
var o3a = {y_: 3, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o3a);
|
||||
verify_DB_('Adding connection #3a', [o1, o2, o3a, o4], db);
|
||||
|
||||
var o3b = {y_: 3, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o3b);
|
||||
verify_DB_('Adding connection #3b', [o1, o2, o3b, o3a, o4], db);
|
||||
}
|
||||
|
||||
function test_DB_removeConnection() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
var o1 = {y_: 1, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
var o2 = {y_: 2, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
var o3a = {y_: 3, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
var o3b = {y_: 3, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
var o3c = {y_: 3, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
var o4 = {y_: 4, sourceBlock_: {},
|
||||
getSourceBlock: Blockly.Connection.prototype.getSourceBlock};
|
||||
db.addConnection(o1);
|
||||
db.addConnection(o2);
|
||||
db.addConnection(o3c);
|
||||
db.addConnection(o3b);
|
||||
db.addConnection(o3a);
|
||||
db.addConnection(o4);
|
||||
verify_DB_('Adding connections 1-4', [o1, o2, o3a, o3b, o3c, o4], db);
|
||||
|
||||
db.removeConnection_(o2);
|
||||
verify_DB_('Removing connection #2', [o1, o3a, o3b, o3c, o4], db);
|
||||
|
||||
db.removeConnection_(o4);
|
||||
verify_DB_('Removing connection #4', [o1, o3a, o3b, o3c], db);
|
||||
|
||||
db.removeConnection_(o1);
|
||||
verify_DB_('Removing connection #1', [o3a, o3b, o3c], db);
|
||||
|
||||
db.removeConnection_(o3a);
|
||||
verify_DB_('Removing connection #3a', [o3b, o3c], db);
|
||||
|
||||
db.removeConnection_(o3c);
|
||||
verify_DB_('Removing connection #3c', [o3b], db);
|
||||
|
||||
db.removeConnection_(o3b);
|
||||
verify_DB_('Removing connection #3b', [], db);
|
||||
}
|
||||
|
||||
function test_DB_getNeighbours() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
|
||||
// Search an empty list.
|
||||
assertEquals(helper_getNeighbours(db,
|
||||
10 /* x */, 10 /* y */, 100 /* radius */).length, 0);
|
||||
|
||||
// Set up some connections.
|
||||
for (var i = 0; i < 10; i++) {
|
||||
db.addConnection(helper_createConnection(0, i,
|
||||
Blockly.PREVIOUS_STATEMENT, null, true));
|
||||
}
|
||||
|
||||
// Test block belongs at beginning.
|
||||
var result = helper_getNeighbours(db, 0, 0, 4);
|
||||
assertEquals(5, result.length);
|
||||
for (i = 0; i < result.length; i++) {
|
||||
assertNotEquals(result.indexOf(db[i]), -1); // contains
|
||||
}
|
||||
|
||||
// Test block belongs at middle.
|
||||
result = helper_getNeighbours(db, 0, 4, 2);
|
||||
assertEquals(5, result.length);
|
||||
for (i = 0; i < result.length; i++) {
|
||||
assertNotEquals(result.indexOf(db[i + 2]), -1); // contains
|
||||
}
|
||||
|
||||
// Test block belongs at end.
|
||||
result = helper_getNeighbours(db, 0, 9, 4);
|
||||
assertEquals(5, result.length);
|
||||
for (i = 0; i < result.length; i++) {
|
||||
assertNotEquals(result.indexOf(db[i + 5]), -1); // contains
|
||||
}
|
||||
|
||||
// Test block has no neighbours due to being out of range in the x direction.
|
||||
result = helper_getNeighbours(db, 10, 9, 4);
|
||||
assertEquals(result.length, 0);
|
||||
|
||||
// Test block has no neighbours due to being out of range in the y direction.
|
||||
result = helper_getNeighbours(db, 0, 19, 4);
|
||||
assertEquals(result.length, 0);
|
||||
|
||||
// Test block has no neighbours due to being out of range diagonally.
|
||||
result = helper_getNeighbours(db, -2, -2, 2);
|
||||
assertEquals(result.length, 0);
|
||||
}
|
||||
|
||||
function test_DB_findPositionForConnection() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
db.addConnection(helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT,
|
||||
null, true));
|
||||
db.addConnection(helper_createConnection(0, 1, Blockly.PREVIOUS_STATEMENT,
|
||||
null, true));
|
||||
db.addConnection(helper_createConnection(0, 2, Blockly.PREVIOUS_STATEMENT,
|
||||
null, true));
|
||||
db.addConnection(helper_createConnection(0, 4, Blockly.PREVIOUS_STATEMENT,
|
||||
null, true));
|
||||
db.addConnection(helper_createConnection(0, 5, Blockly.PREVIOUS_STATEMENT,
|
||||
null, true));
|
||||
|
||||
assertEquals(5, db.length);
|
||||
var conn = helper_createConnection(0, 3, Blockly.PREVIOUS_STATEMENT, null,
|
||||
true);
|
||||
assertEquals(3, db.findPositionForConnection_(conn));
|
||||
}
|
||||
|
||||
function test_DB_findConnection() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
for (var i = 0; i < 10; i++) {
|
||||
db.addConnection(helper_createConnection(i, 0,
|
||||
Blockly.PREVIOUS_STATEMENT, null, true));
|
||||
db.addConnection(helper_createConnection(0, i,
|
||||
Blockly.PREVIOUS_STATEMENT, null, true));
|
||||
}
|
||||
|
||||
var conn = helper_createConnection(3, 3, Blockly.PREVIOUS_STATEMENT, null,
|
||||
true);
|
||||
db.addConnection(conn);
|
||||
assertEquals(conn, db[db.findConnection(conn)]);
|
||||
|
||||
conn = helper_createConnection(3, 3, Blockly.PREVIOUS_STATEMENT, null, true);
|
||||
assertEquals(-1, db.findConnection(conn));
|
||||
}
|
||||
|
||||
function test_DB_ordering() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
for (var i = 0; i < 10; i++) {
|
||||
db.addConnection(helper_createConnection(0, 9 - i,
|
||||
Blockly.PREVIOUS_STATEMENT), null, true);
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
assertEquals(i, db[i].y_);
|
||||
}
|
||||
|
||||
// quasi-random
|
||||
var xCoords = [-29, -47, -77, 2, 43, 34, -59, -52, -90, -36, -91, 38, 87, -20,
|
||||
60, 4, -57, 65, -37, -81, 57, 58, -96, 1, 67, -79, 34, 93, -90, -99, -62,
|
||||
4, 11, -36, -51, -72, 3, -50, -24, -45, -92, -38, 37, 24, -47, -73, 79,
|
||||
-20, 99, 43, -10, -87, 19, 35, -62, -36, 49, 86, -24, -47, -89, 33, -44,
|
||||
25, -73, -91, 85, 6, 0, 89, -94, 36, -35, 84, -9, 96, -21, 52, 10, -95, 7,
|
||||
-67, -70, 62, 9, -40, -95, -9, -94, 55, 57, -96, 55, 8, -48, -57, -87, 81,
|
||||
23, 65];
|
||||
var yCoords = [-81, 82, 5, 47, 30, 57, -12, 28, 38, 92, -25, -20, 23, -51, 73,
|
||||
-90, 8, 28, -51, -15, 81, -60, -6, -16, 77, -62, -42, -24, 35, 95, -46,
|
||||
-7, 61, -16, 14, 91, 57, -38, 27, -39, 92, 47, -98, 11, -33, -72, 64, 38,
|
||||
-64, -88, -35, -59, -76, -94, 45, -25, -100, -95, 63, -97, 45, 98, 99, 34,
|
||||
27, 52, -18, -45, 66, -32, -38, 70, -73, -23, 5, -2, -13, -9, 48, 74, -97,
|
||||
-11, 35, -79, -16, -77, 83, -57, -53, 35, -44, 100, -27, -15, 5, 39, 33,
|
||||
-19, -20, -95];
|
||||
for (i = 0; i < xCoords.length; i++) {
|
||||
db.addConnection(helper_createConnection(xCoords[i], yCoords[i],
|
||||
Blockly.PREVIOUS_STATEMENT), null, true);
|
||||
}
|
||||
|
||||
for (i = 1; i < xCoords.length; i++) {
|
||||
assertTrue(db[i].y_ >= db[i - 1].y_);
|
||||
}
|
||||
}
|
||||
|
||||
function test_SearchForClosest() {
|
||||
var db = new Blockly.ConnectionDB();
|
||||
var sharedWorkspace = {id: "Shared workspace"};
|
||||
|
||||
// Search an empty list.
|
||||
assertEquals(null, helper_searchDB(db, 10 /* x */, 10 /* y */,
|
||||
100 /* radius */));
|
||||
|
||||
db.addConnection(helper_createConnection(100, 0, Blockly.PREVIOUS_STATEMENT,
|
||||
sharedWorkspace, true));
|
||||
assertEquals(null, helper_searchDB(db, 0, 0, 5, sharedWorkspace));
|
||||
|
||||
db = new Blockly.ConnectionDB();
|
||||
for (var i = 0; i < 10; i++) {
|
||||
var tempConn = helper_createConnection(0, i, Blockly.PREVIOUS_STATEMENT,
|
||||
sharedWorkspace, true);
|
||||
tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
db.addConnection(tempConn);
|
||||
}
|
||||
|
||||
// Should be at 0, 9.
|
||||
var last = db[db.length - 1];
|
||||
// Correct connection is last in db; many connections in radius.
|
||||
assertEquals(last, helper_searchDB(db, 0, 10, 15, sharedWorkspace));
|
||||
// Nothing nearby.
|
||||
assertEquals(null, helper_searchDB(db, 100, 100, 3, sharedWorkspace));
|
||||
// First in db, exact match.
|
||||
assertEquals(db[0], helper_searchDB(db, 0, 0, 0, sharedWorkspace));
|
||||
|
||||
tempConn = helper_createConnection(6, 6, Blockly.PREVIOUS_STATEMENT,
|
||||
sharedWorkspace, true);
|
||||
tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
db.addConnection(tempConn);
|
||||
tempConn = helper_createConnection(5, 5, Blockly.PREVIOUS_STATEMENT,
|
||||
sharedWorkspace, true);
|
||||
tempConn.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
db.addConnection(tempConn);
|
||||
|
||||
var result = helper_searchDB(db, 4, 6, 3, sharedWorkspace);
|
||||
assertEquals(5, result.x_);
|
||||
assertEquals(5, result.y_);
|
||||
}
|
||||
|
||||
|
||||
function helper_getNeighbours(db, x, y, radius) {
|
||||
return db.getNeighbours(helper_createConnection(x, y, Blockly.NEXT_STATEMENT,
|
||||
null, true),
|
||||
radius);
|
||||
}
|
||||
|
||||
function helper_searchDB(db, x, y, radius, shared_workspace) {
|
||||
var tempConn = helper_createConnection(x, y,
|
||||
Blockly.NEXT_STATEMENT, shared_workspace, true);
|
||||
tempConn.sourceBlock_ = helper_makeSourceBlock(shared_workspace);
|
||||
var closest = db.searchForClosest(tempConn, radius, {x: 0, y: 0});
|
||||
return closest.connection;
|
||||
}
|
||||
|
||||
function helper_makeSourceBlock(sharedWorkspace) {
|
||||
return {workspace: sharedWorkspace,
|
||||
parentBlock_: null,
|
||||
getParent: function() { return null; },
|
||||
movable_: true,
|
||||
isMovable: function() { return true; },
|
||||
isShadow: function() { return false; }
|
||||
};
|
||||
}
|
||||
|
||||
function helper_createConnection(x, y, type, opt_shared_workspace,
|
||||
opt_rendered) {
|
||||
var workspace = opt_shared_workspace ? opt_shared_workspace : {};
|
||||
if (opt_rendered) {
|
||||
var conn = new Blockly.RenderedConnection({workspace: workspace}, type);
|
||||
} else {
|
||||
var conn = new Blockly.Connection({workspace: workspace}, type);
|
||||
}
|
||||
conn.x_ = x;
|
||||
conn.y_ = y;
|
||||
return conn;
|
||||
}
|
||||
324
node_modules/node-blockly/blockly/tests/jsunit/connection_test.js
generated
vendored
Normal file
324
node_modules/node-blockly/blockly/tests/jsunit/connection_test.js
generated
vendored
Normal file
@@ -0,0 +1,324 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2016 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for connection logic.
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var input;
|
||||
var output;
|
||||
var previous;
|
||||
var next;
|
||||
|
||||
var dummyWorkspace;
|
||||
|
||||
function connectionTest_setUp() {
|
||||
dummyWorkspace = {};
|
||||
function createDummyBlock() {
|
||||
return {
|
||||
workspace: dummyWorkspace,
|
||||
isShadow: function() {return false;}
|
||||
};
|
||||
}
|
||||
input = new Blockly.Connection(createDummyBlock(),
|
||||
Blockly.INPUT_VALUE);
|
||||
output = new Blockly.Connection(createDummyBlock(),
|
||||
Blockly.OUTPUT_VALUE);
|
||||
previous = new Blockly.Connection(createDummyBlock(),
|
||||
Blockly.PREVIOUS_STATEMENT);
|
||||
next = new Blockly.Connection(createDummyBlock(),
|
||||
Blockly.NEXT_STATEMENT);
|
||||
}
|
||||
|
||||
function connectionTest_tearDown() {
|
||||
input = null;
|
||||
output = null;
|
||||
previous = null;
|
||||
next = null;
|
||||
dummyWorkspace = null;
|
||||
}
|
||||
|
||||
var isMovableFn = function() { return true; };
|
||||
/**
|
||||
* These tests check that the reasons for failures to connect are consistent
|
||||
* (internal view of error states).
|
||||
*/
|
||||
function testCanConnectWithReason_TargetNull() {
|
||||
connectionTest_setUp();
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_TARGET_NULL,
|
||||
input.canConnectWithReason_(null));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCanConnectWithReason_Disconnect() {
|
||||
connectionTest_setUp();
|
||||
|
||||
var tempConnection = new Blockly.Connection({workspace: dummyWorkspace, isMovable: isMovableFn},
|
||||
Blockly.OUTPUT_VALUE);
|
||||
Blockly.Connection.connectReciprocally_(input, tempConnection);
|
||||
assertEquals(Blockly.Connection.CAN_CONNECT,
|
||||
input.canConnectWithReason_(output));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCanConnectWithReason_DifferentWorkspaces() {
|
||||
connectionTest_setUp();
|
||||
|
||||
input = new Blockly.Connection({workspace: {}}, Blockly.INPUT_VALUE);
|
||||
output = new Blockly.Connection({workspace: dummyWorkspace},
|
||||
Blockly.OUTPUT_VALUE);
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_DIFFERENT_WORKSPACES,
|
||||
input.canConnectWithReason_(output));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
|
||||
function testCanConnectWithReason_Self() {
|
||||
connectionTest_setUp();
|
||||
|
||||
var block = {type_: "test block"};
|
||||
input.sourceBlock_ = block;
|
||||
assertEquals(Blockly.Connection.REASON_SELF_CONNECTION,
|
||||
input.canConnectWithReason_(input));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCanConnectWithReason_Type() {
|
||||
connectionTest_setUp();
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
input.canConnectWithReason_(previous));
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
input.canConnectWithReason_(next));
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
output.canConnectWithReason_(previous));
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
output.canConnectWithReason_(next));
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
previous.canConnectWithReason_(input));
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
previous.canConnectWithReason_(output));
|
||||
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
next.canConnectWithReason_(input));
|
||||
assertEquals(Blockly.Connection.REASON_WRONG_TYPE,
|
||||
next.canConnectWithReason_(output));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCanConnectWithReason_CanConnect() {
|
||||
connectionTest_setUp();
|
||||
|
||||
assertEquals(Blockly.Connection.CAN_CONNECT,
|
||||
previous.canConnectWithReason_(next));
|
||||
assertEquals(Blockly.Connection.CAN_CONNECT,
|
||||
next.canConnectWithReason_(previous));
|
||||
assertEquals(Blockly.Connection.CAN_CONNECT,
|
||||
input.canConnectWithReason_(output));
|
||||
assertEquals(Blockly.Connection.CAN_CONNECT,
|
||||
output.canConnectWithReason_(input));
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* The next set of tests checks that exceptions are being thrown at the correct
|
||||
* times (external view of errors).
|
||||
*/
|
||||
function testCheckConnection_Self() {
|
||||
connectionTest_setUp();
|
||||
var block = {type_: "test block"};
|
||||
input.sourceBlock_ = block;
|
||||
try {
|
||||
input.checkConnection_(input);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypeInputPrev() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
input.checkConnection_(previous);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypeInputNext() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
input.checkConnection_(next);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypeOutputPrev() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
output.checkConnection_(previous);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypePrevInput() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
previous.checkConnection_(input);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypePrevOutput() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
previous.checkConnection_(output);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypeNextInput() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
next.checkConnection_(input);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function testCheckConnection_TypeNextOutput() {
|
||||
connectionTest_setUp();
|
||||
try {
|
||||
next.checkConnection_(output);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
|
||||
function test_isConnectionAllowed_Distance() {
|
||||
var sharedWorkspace = {};
|
||||
// Two connections of opposite types near each other.
|
||||
var one = helper_createConnection(5 /* x */, 10 /* y */,
|
||||
Blockly.INPUT_VALUE, null, true);
|
||||
one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
var two = helper_createConnection(10 /* x */, 15 /* y */,
|
||||
Blockly.OUTPUT_VALUE, null, true);
|
||||
two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
assertTrue(one.isConnectionAllowed(two, 20.0));
|
||||
// Move connections farther apart.
|
||||
two.x_ = 100;
|
||||
two.y_ = 100;
|
||||
assertFalse(one.isConnectionAllowed(two, 20.0));
|
||||
}
|
||||
|
||||
function test_isConnectionAllowed_Unrendered() {
|
||||
var sharedWorkspace = {};
|
||||
|
||||
var one = helper_createConnection(5 /* x */, 10 /* y */,
|
||||
Blockly.INPUT_VALUE);
|
||||
one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
// Don't offer to connect an already connected left (male) value plug to
|
||||
// an available right (female) value plug.
|
||||
var two = helper_createConnection(0, 0, Blockly.OUTPUT_VALUE);
|
||||
two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
assertTrue(one.isConnectionAllowed(two));
|
||||
var three = helper_createConnection(0, 0, Blockly.INPUT_VALUE);
|
||||
three.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
Blockly.Connection.connectReciprocally_(two, three);
|
||||
assertFalse(one.isConnectionAllowed(two));
|
||||
|
||||
// Don't connect two connections on the same block.
|
||||
two.sourceBlock_ = one.sourceBlock_;
|
||||
assertFalse(one.isConnectionAllowed(two));
|
||||
}
|
||||
|
||||
function test_isConnectionAllowed_NoNext() {
|
||||
var sharedWorkspace = {};
|
||||
var one = helper_createConnection(0, 0, Blockly.NEXT_STATEMENT);
|
||||
one.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
one.sourceBlock_.nextConnection = one;
|
||||
|
||||
var two = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT);
|
||||
two.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
|
||||
assertTrue(two.isConnectionAllowed(one));
|
||||
|
||||
var three = helper_createConnection(0, 0, Blockly.PREVIOUS_STATEMENT);
|
||||
three.sourceBlock_ = helper_makeSourceBlock(sharedWorkspace);
|
||||
three.sourceBlock_.previousConnection = three;
|
||||
Blockly.Connection.connectReciprocally_(one, three);
|
||||
|
||||
// A terminal block is allowed to replace another terminal block.
|
||||
assertTrue(two.isConnectionAllowed(one));
|
||||
}
|
||||
|
||||
function testCheckConnection_Okay() {
|
||||
connectionTest_setUp();
|
||||
previous.checkConnection_(next);
|
||||
next.checkConnection_(previous);
|
||||
input.checkConnection_(output);
|
||||
output.checkConnection_(input);
|
||||
|
||||
connectionTest_tearDown();
|
||||
}
|
||||
746
node_modules/node-blockly/blockly/tests/jsunit/event_test.js
generated
vendored
Normal file
746
node_modules/node-blockly/blockly/tests/jsunit/event_test.js
generated
vendored
Normal file
@@ -0,0 +1,746 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.Events
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
var mockControl_;
|
||||
var workspace;
|
||||
var savedFireFunc = Blockly.Events.fire;
|
||||
|
||||
function temporary_fireEvent(event) {
|
||||
if (!Blockly.Events.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Blockly.Events.FIRE_QUEUE_.push(event);
|
||||
Blockly.Events.fireNow_();
|
||||
}
|
||||
|
||||
function eventTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
}
|
||||
|
||||
function eventTest_setUpWithMockBlocks() {
|
||||
eventTest_setUp();
|
||||
// TODO: Replace with defineGetVarBlock();
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
'type': 'field_variable_test_block',
|
||||
'message0': '%1',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': 'item'
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
'type': 'simple_test_block',
|
||||
'message0': 'simple test block'
|
||||
}]);
|
||||
}
|
||||
|
||||
function eventTest_tearDown() {
|
||||
delete Blockly.Blocks['field_variable_test_block'];
|
||||
delete Blockly.Blocks['simple_test_block'];
|
||||
mockControl_.$tearDown();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function eventTest_tearDownWithMockBlocks() {
|
||||
eventTest_tearDown();
|
||||
delete Blockly.Blocks.field_variable_test_block;
|
||||
}
|
||||
|
||||
function test_block_base_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, '1');
|
||||
try {
|
||||
var block = createSimpleTestBlock(workspace);
|
||||
|
||||
// Here's the event we care about.
|
||||
var event = new Blockly.Events.BlockBase(block);
|
||||
assertUndefined(event.varId);
|
||||
checkExactEventValues(event, {'blockId': '1', 'workspaceId': workspace.id,
|
||||
'group': '', 'recordUndo': true});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_var_base_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, '1');
|
||||
try {
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
|
||||
var event = new Blockly.Events.VarBase(variable);
|
||||
assertUndefined(event.blockId);
|
||||
checkExactEventValues(event, {'varId': 'id1',
|
||||
'workspaceId': workspace.id, 'group': '', 'recordUndo': true});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_abstract_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var event = new Blockly.Events.Abstract();
|
||||
assertUndefined(event.blockId);
|
||||
assertUndefined(event.workspaceId);
|
||||
assertUndefined(event.varId);
|
||||
checkExactEventValues(event, {'group': '', 'recordUndo': true});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
// Test util
|
||||
function checkCreateEventValues(event, block, ids, type) {
|
||||
var expected_xml = Blockly.Xml.domToText(Blockly.Xml.blockToDom(block));
|
||||
var result_xml = Blockly.Xml.domToText(event.xml);
|
||||
assertEquals(expected_xml, result_xml);
|
||||
isEqualArrays(ids, event.ids);
|
||||
assertEquals(type, event.type);
|
||||
}
|
||||
|
||||
// Test util
|
||||
function checkDeleteEventValues(event, block, ids, type) {
|
||||
var expected_xml = Blockly.Xml.domToText(Blockly.Xml.blockToDom(block));
|
||||
var result_xml = Blockly.Xml.domToText(event.oldXml);
|
||||
assertEquals(expected_xml, result_xml);
|
||||
isEqualArrays(ids, event.ids);
|
||||
assertEquals(type, event.type);
|
||||
}
|
||||
|
||||
// Test util
|
||||
function checkExactEventValues(event, values) {
|
||||
var keys = Object.keys(values);
|
||||
for (var i = 0, field; field = keys[i]; i++) {
|
||||
assertEquals(values[field], event[field]);
|
||||
}
|
||||
}
|
||||
|
||||
// Test util
|
||||
function createSimpleTestBlock(workspace) {
|
||||
// Disable events while constructing the block: this is a test of the
|
||||
// Blockly.Event constructors, not the block constructor.
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'simple_test_block');
|
||||
Blockly.Events.enable();
|
||||
return block;
|
||||
}
|
||||
|
||||
function test_create_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
var block = createSimpleTestBlock(workspace);
|
||||
|
||||
var event = new Blockly.Events.Create(block);
|
||||
checkCreateEventValues(event, block, ['1'], 'create');
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockCreate_constructor() {
|
||||
// expect that blockCreate behaves the same as create.
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
var block = createSimpleTestBlock(workspace);
|
||||
|
||||
var event = new Blockly.Events.BlockCreate(block);
|
||||
checkCreateEventValues(event, block, ['1'], 'create');
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_delete_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
var block = createSimpleTestBlock(workspace);
|
||||
var event = new Blockly.Events.Delete(block);
|
||||
checkDeleteEventValues(event, block, ['1'], 'delete');
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockDelete_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
var block = createSimpleTestBlock(workspace);
|
||||
var event = new Blockly.Events.BlockDelete(block);
|
||||
checkDeleteEventValues(event, block, ['1'], 'delete');
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_change_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'field_variable_test_block');
|
||||
Blockly.Events.enable();
|
||||
|
||||
var event = new Blockly.Events.Change(block, 'field', 'VAR', 'id1', 'id2');
|
||||
checkExactEventValues(event, {'element': 'field', 'name': 'VAR',
|
||||
'oldValue': 'id1', 'newValue': 'id2', 'type': 'change'});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockChange_constructor() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
try {
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'field_variable_test_block');
|
||||
Blockly.Events.enable();
|
||||
|
||||
var event = new Blockly.Events.BlockChange(block, 'field', 'VAR', 'id1',
|
||||
'id2');
|
||||
checkExactEventValues(event, {'element': 'field', 'name': 'VAR',
|
||||
'oldValue': 'id1', 'newValue': 'id2', 'type': 'change'});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_move_constructorCoordinate() {
|
||||
// Expect the oldCoordinate to be set.
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
var block1 = createSimpleTestBlock(workspace);
|
||||
var coordinate = new goog.math.Coordinate(3,4);
|
||||
block1.xy_ = coordinate;
|
||||
|
||||
var event = new Blockly.Events.Move(block1);
|
||||
checkExactEventValues(event, {'oldCoordinate': coordinate,
|
||||
'type': 'move'});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_move_constructoroldParentId() {
|
||||
// Expect the oldParentId to be set but not the oldCoordinate to be set.
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
var block1 = createSimpleTestBlock(workspace);
|
||||
var block2 = createSimpleTestBlock(workspace);
|
||||
block1.parentBlock_ = block2;
|
||||
block1.xy_ = new goog.math.Coordinate(3,4);
|
||||
|
||||
var event = new Blockly.Events.Move(block1);
|
||||
checkExactEventValues(event, {'oldCoordinate': undefined,
|
||||
'oldParentId': '2', 'type': 'move'});
|
||||
block1.parentBlock_ = null;
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockMove_constructorCoordinate() {
|
||||
// Expect the oldCoordinate to be set.
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
var block1 = createSimpleTestBlock(workspace);
|
||||
var coordinate = new goog.math.Coordinate(3,4);
|
||||
block1.xy_ = coordinate;
|
||||
|
||||
var event = new Blockly.Events.BlockMove(block1);
|
||||
checkExactEventValues(event, {'oldCoordinate': coordinate,
|
||||
'type': 'move'});
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockMove_constructoroldParentId() {
|
||||
// Expect the oldParentId to be set but not the oldCoordinate to be set.
|
||||
eventTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
var block1 = createSimpleTestBlock(workspace);
|
||||
var block2 = createSimpleTestBlock(workspace);
|
||||
block1.parentBlock_ = block2;
|
||||
block1.xy_ = new goog.math.Coordinate(3,4);
|
||||
|
||||
var event = new Blockly.Events.BlockMove(block1);
|
||||
checkExactEventValues(event, {'oldCoordinate': undefined,
|
||||
'oldParentId': '2', 'type': 'move'});
|
||||
block1.parentBlock_ = null;
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_varCreate_constructor() {
|
||||
eventTest_setUp();
|
||||
try {
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarCreate(variable);
|
||||
checkExactEventValues(event, {'varName': 'name1', 'varType': 'type1',
|
||||
'type': 'var_create'});
|
||||
} finally {
|
||||
eventTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_varCreate_toJson() {
|
||||
eventTest_setUp();
|
||||
try {
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarCreate(variable);
|
||||
var json = event.toJson();
|
||||
var expectedJson = ({type: "var_create", varId: "id1", varType: "type1",
|
||||
varName: "name1"});
|
||||
|
||||
assertEquals(JSON.stringify(expectedJson), JSON.stringify(json));
|
||||
} finally {
|
||||
eventTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_varCreate_fromJson() {
|
||||
eventTest_setUp();
|
||||
try {
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarCreate(variable);
|
||||
var event2 = new Blockly.Events.VarCreate(null);
|
||||
var json = event.toJson();
|
||||
event2.fromJson(json);
|
||||
|
||||
assertEquals(JSON.stringify(json), JSON.stringify(event2.toJson()));
|
||||
} finally {
|
||||
eventTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_varCreate_runForward() {
|
||||
eventTest_setUp();
|
||||
var json = {type: "var_create", varId: "id1", varType: "type1",
|
||||
varName: "name1"};
|
||||
var event = Blockly.Events.fromJson(json, workspace);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
event.run(true);
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varCreate_runBackwards() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarCreate(variable);
|
||||
assertNotNull(workspace.getVariableById('id1'));
|
||||
event.run(false);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varDelete_constructor() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarDelete(variable);
|
||||
checkExactEventValues(event, {'varName': 'name1', 'varType': 'type1',
|
||||
'varId':'id1', 'type': 'var_delete'});
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varDelete_toJson() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarDelete(variable);
|
||||
var json = event.toJson();
|
||||
var expectedJson = ({type: "var_delete", varId: "id1", varType: "type1",
|
||||
varName: "name1"});
|
||||
|
||||
assertEquals(JSON.stringify(expectedJson), JSON.stringify(json));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varDelete_fromJson() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarDelete(variable);
|
||||
var event2 = new Blockly.Events.VarDelete(null);
|
||||
var json = event.toJson();
|
||||
event2.fromJson(json);
|
||||
|
||||
assertEquals(JSON.stringify(json), JSON.stringify(event2.toJson()));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varDelete_runForwards() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarDelete(variable);
|
||||
assertNotNull(workspace.getVariableById('id1'));
|
||||
event.run(true);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varDelete_runBackwards() {
|
||||
eventTest_setUp();
|
||||
var json = {type: "var_delete", varId: "id1", varType: "type1",
|
||||
varName: "name1"};
|
||||
var event = Blockly.Events.fromJson(json, workspace);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
event.run(false);
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varRename_constructor() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarRename(variable, 'name2');
|
||||
checkExactEventValues(event, {'varId': 'id1', 'oldName': 'name1',
|
||||
'newName': 'name2', 'type': 'var_rename'});
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varRename_toJson() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarRename(variable, 'name2');
|
||||
var json = event.toJson();
|
||||
var expectedJson = ({type: "var_rename", varId: "id1", oldName: "name1",
|
||||
newName: "name2"});
|
||||
|
||||
assertEquals(JSON.stringify(expectedJson), JSON.stringify(json));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varRename_fromJson() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarRename(variable, '');
|
||||
var event2 = new Blockly.Events.VarRename(null);
|
||||
var json = event.toJson();
|
||||
event2.fromJson(json);
|
||||
|
||||
assertEquals(JSON.stringify(json), JSON.stringify(event2.toJson()));
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varRename_runForward() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarRename(variable, 'name2');
|
||||
event.run(true);
|
||||
assertNull(workspace.getVariable('name1'));
|
||||
checkVariableValues(workspace, 'name2', 'type1', 'id1');
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_varBackard_runForward() {
|
||||
eventTest_setUp();
|
||||
var variable = workspace.createVariable('name1', 'type1', 'id1');
|
||||
var event = new Blockly.Events.VarRename(variable, 'name2');
|
||||
event.run(false);
|
||||
assertNull(workspace.getVariable('name2'));
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
eventTest_tearDown();
|
||||
}
|
||||
|
||||
function test_events_filter() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
new Blockly.Events.BlockCreate(block1),
|
||||
new Blockly.Events.BlockMove(block1),
|
||||
new Blockly.Events.BlockChange(block1, 'field', 'VAR', 'id1', 'id2'),
|
||||
new Blockly.Events.Ui(block1, 'click')
|
||||
];
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(4, filteredEvents.length); // no event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
assertTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assertTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assertTrue(filteredEvents[2] instanceof Blockly.Events.BlockChange);
|
||||
assertTrue(filteredEvents[3] instanceof Blockly.Events.Ui);
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_events_filterForward() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
new Blockly.Events.BlockCreate(block1),
|
||||
];
|
||||
helper_addMoveEvent(events, block1, 1, 1);
|
||||
helper_addMoveEvent(events, block1, 2, 2);
|
||||
helper_addMoveEvent(events, block1, 3, 3);
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(2, filteredEvents.length); // duplicate moves should have been removed.
|
||||
// test that the order hasn't changed
|
||||
assertTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assertTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assertEquals(3, filteredEvents[1].newCoordinate.x);
|
||||
assertEquals(3, filteredEvents[1].newCoordinate.y);
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_events_filterBackward() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
new Blockly.Events.BlockCreate(block1),
|
||||
];
|
||||
helper_addMoveEvent(events, block1, 1, 1);
|
||||
helper_addMoveEvent(events, block1, 2, 2);
|
||||
helper_addMoveEvent(events, block1, 3, 3);
|
||||
var filteredEvents = Blockly.Events.filter(events, false);
|
||||
assertEquals(2, filteredEvents.length); // duplicate event should have been removed.
|
||||
// test that the order hasn't changed
|
||||
assertTrue(filteredEvents[0] instanceof Blockly.Events.BlockCreate);
|
||||
assertTrue(filteredEvents[1] instanceof Blockly.Events.BlockMove);
|
||||
assertEquals(1, filteredEvents[1].newCoordinate.x);
|
||||
assertEquals(1, filteredEvents[1].newCoordinate.y);
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_events_filterDifferentBlocks() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var block2 = workspace.newBlock('field_variable_test_block', '2');
|
||||
var events = [
|
||||
new Blockly.Events.BlockCreate(block1),
|
||||
new Blockly.Events.BlockMove(block1),
|
||||
new Blockly.Events.BlockCreate(block2),
|
||||
new Blockly.Events.BlockMove(block2)
|
||||
];
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(4, filteredEvents.length); // no event should have been removed.
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_events_mergeMove() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [];
|
||||
helper_addMoveEvent(events, block1, 0, 0);
|
||||
helper_addMoveEvent(events, block1, 1, 1);
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(1, filteredEvents.length); // second move event merged into first
|
||||
assertEquals(1, filteredEvents[0].newCoordinate.x);
|
||||
assertEquals(1, filteredEvents[0].newCoordinate.y);
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_events_mergeChange() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
new Blockly.Events.Change(block1, 'field', 'VAR', 'item', 'item1'),
|
||||
new Blockly.Events.Change(block1, 'field', 'VAR', 'item1', 'item2')
|
||||
];
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(1, filteredEvents.length); // second change event merged into first
|
||||
assertEquals('item', filteredEvents[0].oldValue);
|
||||
assertEquals('item2', filteredEvents[0].newValue);
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_events_mergeUi() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block1 = workspace.newBlock('field_variable_test_block', '1');
|
||||
var block2 = workspace.newBlock('field_variable_test_block', '2');
|
||||
var block3 = workspace.newBlock('field_variable_test_block', '3');
|
||||
var events = [
|
||||
new Blockly.Events.Ui(block1, 'commentOpen', 'false', 'true'),
|
||||
new Blockly.Events.Ui(block1, 'click', 'false', 'true'),
|
||||
new Blockly.Events.Ui(block2, 'mutatorOpen', 'false', 'true'),
|
||||
new Blockly.Events.Ui(block2, 'click', 'false', 'true'),
|
||||
new Blockly.Events.Ui(block3, 'warningOpen', 'false', 'true'),
|
||||
new Blockly.Events.Ui(block3, 'click', 'false', 'true')
|
||||
];
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
assertEquals(3, filteredEvents.length); // click event merged into corresponding *Open event
|
||||
assertEquals('commentOpen', filteredEvents[0].element);
|
||||
assertEquals('mutatorOpen', filteredEvents[1].element);
|
||||
assertEquals('warningOpen', filteredEvents[2].element);
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that events that collide on a (event, block, workspace) tuple
|
||||
* but cannot be merged do not get dropped during filtering.
|
||||
*/
|
||||
function test_events_stackclick() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block = workspace.newBlock('field_variable_test_block', '1');
|
||||
var events = [
|
||||
new Blockly.Events.Ui(block, 'click', undefined, undefined),
|
||||
new Blockly.Events.Ui(block, 'stackclick', undefined, undefined)
|
||||
];
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
// click and stackclick should both exist
|
||||
assertEquals(2, filteredEvents.length);
|
||||
assertEquals('click', filteredEvents[0].element);
|
||||
assertEquals('stackclick', filteredEvents[1].element);
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutator composition could result in move events for blocks
|
||||
* connected to the mutated block that were null operations. This
|
||||
* leads to events in the undo/redo queue that do nothing, requiring
|
||||
* an extra undo/redo to proceed to the next event. This test ensures
|
||||
* that two move events that do get merged (disconnecting and
|
||||
* reconnecting a block in response to a mutator change) are filtered
|
||||
* from the queue.
|
||||
*/
|
||||
function test_events_filteraftermerge() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
var block = workspace.newBlock('field_variable_test_block', '1');
|
||||
block.setParent(null);
|
||||
var events = [];
|
||||
helper_addMoveEventParent(events, block, null);
|
||||
helper_addMoveEventParent(events, block, null);
|
||||
var filteredEvents = Blockly.Events.filter(events, true);
|
||||
// The two events should be merged, but because nothing has changed
|
||||
// they will be filtered out.
|
||||
assertEquals(0, filteredEvents.length);
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to simulate block move events.
|
||||
*
|
||||
* @param {!Array.<Blockly.Events.Abstract>} events a queue of events.
|
||||
* @param {!Blockly.Block} block the block to be moved
|
||||
* @param {number} newX new X coordinate of the block
|
||||
* @param {number} newY new Y coordinate of the block
|
||||
*/
|
||||
function helper_addMoveEvent(events, block, newX, newY) {
|
||||
events.push(new Blockly.Events.BlockMove(block));
|
||||
block.xy_ = new goog.math.Coordinate(newX, newY);
|
||||
events[events.length-1].recordNew();
|
||||
}
|
||||
|
||||
function helper_addMoveEventParent(events, block, parent) {
|
||||
events.push(new Blockly.Events.BlockMove(block));
|
||||
block.setParent(parent);
|
||||
events[events.length-1].recordNew();
|
||||
}
|
||||
|
||||
function test_events_newblock_newvar() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
|
||||
Blockly.Events.fire = temporary_fireEvent;
|
||||
temporary_fireEvent.firedEvents_ = [];
|
||||
// Expect three calls to genUid: one to set the block's ID, one for the event
|
||||
// group's id, and one for the variable's ID.
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2', '3']);
|
||||
try {
|
||||
var block = workspace.newBlock('field_variable_test_block');
|
||||
|
||||
var firedEvents = workspace.undoStack_;
|
||||
// Expect two events: varCreate and block create.
|
||||
assertEquals(2, firedEvents.length);
|
||||
|
||||
var event0 = firedEvents[0];
|
||||
var event1 = firedEvents[1];
|
||||
assertEquals('var_create', event0.type);
|
||||
assertEquals('create', event1.type);
|
||||
|
||||
// Expect the events to have the same group ID.
|
||||
assertEquals(event0.group, event1.group);
|
||||
|
||||
// Expect the group ID to be the result of the second call to genUid.
|
||||
assertEquals('2', event0.group);
|
||||
|
||||
// Expect the workspace to have a variable with ID '3'.
|
||||
assertNotNull(workspace.getVariableById('3'));
|
||||
assertEquals('3', event0.varId);
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
Blockly.Events.fire = savedFireFunc;
|
||||
}
|
||||
}
|
||||
|
||||
// The sequence of events should be the same whether the block was created from
|
||||
// XML or directly.
|
||||
function test_events_newblock_newvar_xml() {
|
||||
eventTest_setUpWithMockBlocks();
|
||||
|
||||
Blockly.Events.fire = temporary_fireEvent;
|
||||
temporary_fireEvent.firedEvents_ = [];
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <block type="field_variable_test_block" id="block1">' +
|
||||
' <field name="VAR" id="id1" variabletype="">name1</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
|
||||
var firedEvents = workspace.undoStack_;
|
||||
// Expect two events: varCreate and block create.
|
||||
assertEquals(2, firedEvents.length);
|
||||
|
||||
var event0 = firedEvents[0];
|
||||
var event1 = firedEvents[1];
|
||||
assertEquals('var_create', event0.type);
|
||||
assertEquals('create', event1.type);
|
||||
|
||||
// Expect the events to have the same group ID.
|
||||
assertEquals(event0.group, event1.group);
|
||||
|
||||
// Expect the workspace to have a variable with ID 'id1'.
|
||||
assertNotNull(workspace.getVariableById('id1'));
|
||||
assertEquals('id1', event0.varId);
|
||||
} finally {
|
||||
eventTest_tearDownWithMockBlocks();
|
||||
Blockly.Events.fire = savedFireFunc;
|
||||
}
|
||||
}
|
||||
657
node_modules/node-blockly/blockly/tests/jsunit/extensions_test.js
generated
vendored
Normal file
657
node_modules/node-blockly/blockly/tests/jsunit/extensions_test.js
generated
vendored
Normal file
@@ -0,0 +1,657 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.Extensions
|
||||
* @author Anm@anm.me (Andrew n marshall)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_extension() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['extensions_test']);
|
||||
|
||||
var numCallsToBefore = 0;
|
||||
var numCallsToAfter = 0;
|
||||
|
||||
// Extension defined before the block type is defined.
|
||||
Blockly.Extensions.register('extensions_test_before', function () {
|
||||
numCallsToBefore++;
|
||||
this.extendedWithBefore = true;
|
||||
});
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "extension_test_block",
|
||||
"message0": "extension_test_block",
|
||||
"extensions": ["extensions_test_before", "extensions_test_after"]
|
||||
}]);
|
||||
|
||||
// Extension defined after the block type (but before instantiation).
|
||||
Blockly.Extensions.register('extensions_test_after', function () {
|
||||
numCallsToAfter++;
|
||||
this.extendedWithAfter = true;
|
||||
});
|
||||
|
||||
assert(goog.isFunction(Blockly.Extensions.ALL_['extensions_test_before']));
|
||||
assert(goog.isFunction(Blockly.Extensions.ALL_['extensions_test_after']));
|
||||
assertEquals(0, numCallsToBefore);
|
||||
assertEquals(0, numCallsToAfter);
|
||||
|
||||
block = new Blockly.Block(workspace, 'extension_test_block');
|
||||
|
||||
assertEquals(1, numCallsToBefore);
|
||||
assertEquals(1, numCallsToAfter);
|
||||
assert(block.extendedWithBefore);
|
||||
assert(block.extendedWithAfter);
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
|
||||
delete Blockly.Extensions.ALL_['extensions_test_before'];
|
||||
delete Blockly.Extensions.ALL_['extensions_test_after'];
|
||||
delete Blockly.Blocks['extension_test_block'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_extension_missing() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['missing_extension']);
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "missing_extension_block",
|
||||
"message0": "missing_extension_block",
|
||||
"extensions": ["missing_extension"]
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, 'missing_extension_block');
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks['missing_extension_block'];
|
||||
}
|
||||
assert(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_extension_not_a_function() {
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['extension_just_a_string']);
|
||||
Blockly.Extensions.register('extension_just_a_string', 'extension_just_a_string');
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['extension_just_a_string'];
|
||||
}
|
||||
assert(exceptionWasThrown);
|
||||
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['extension_is_null']);
|
||||
Blockly.Extensions.register('extension_is_null', null);
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['extension_is_null'];
|
||||
}
|
||||
assert(exceptionWasThrown);
|
||||
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['extension_is_undefined']);
|
||||
Blockly.Extensions.register('extension_is_undefined');
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['extension_is_undefined'];
|
||||
}
|
||||
assert(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_parent_tooltip_when_inline() {
|
||||
var defaultTooltip = "defaultTooltip";
|
||||
var parentTooltip = "parentTooltip";
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{
|
||||
"type": "test_parent_tooltip_when_inline",
|
||||
"message0": "test_parent_tooltip_when_inline",
|
||||
"output": true,
|
||||
"tooltip": defaultTooltip,
|
||||
"extensions": ["parent_tooltip_when_inline"]
|
||||
},
|
||||
{
|
||||
"type": "test_parent",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "INPUT"
|
||||
}
|
||||
],
|
||||
"tooltip": parentTooltip
|
||||
}
|
||||
]);
|
||||
|
||||
block = new Blockly.Block(workspace, 'test_parent_tooltip_when_inline');
|
||||
|
||||
// Tooltip is dynamic after extension initialization.
|
||||
assert(goog.isFunction(block.tooltip));
|
||||
assertEquals(block.tooltip(), defaultTooltip);
|
||||
|
||||
// Tooltip is normal before connected to parent.
|
||||
var parent = new Blockly.Block(workspace, 'test_parent');
|
||||
assertEquals(parent.tooltip, parentTooltip);
|
||||
assertFalse(!!parent.inputsInline);
|
||||
|
||||
// Tooltip is normal when parent is not inline.
|
||||
parent.getInput('INPUT').connection.connect(block.outputConnection);
|
||||
assertEquals(block.getParent(), parent);
|
||||
assertEquals(block.tooltip(), defaultTooltip);
|
||||
|
||||
// Tooltip is parent's when parent is inline.
|
||||
parent.setInputsInline(true);
|
||||
assertEquals(block.tooltip(), parentTooltip);
|
||||
|
||||
// Tooltip revert when disconnected.
|
||||
parent.getInput('INPUT').connection.disconnect();
|
||||
assert(!block.getParent());
|
||||
assertEquals(block.tooltip(), defaultTooltip);
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
|
||||
delete Blockly.Blocks['test_parent_tooltip_when_inline'];
|
||||
delete Blockly.Blocks['test_parent'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_mixin_extension() {
|
||||
var TEST_MIXIN = {
|
||||
field: 'FIELD',
|
||||
method: function() {
|
||||
console.log('TEXT_MIXIN method()');
|
||||
}
|
||||
};
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['mixin_test']);
|
||||
|
||||
// Extension defined before the block type is defined.
|
||||
Blockly.Extensions.registerMixin('mixin_test', TEST_MIXIN);
|
||||
assert(goog.isFunction(Blockly.Extensions.ALL_['mixin_test']));
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "test_block_mixin",
|
||||
"message0": "test_block_mixin",
|
||||
"extensions": ["mixin_test"]
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, 'test_block_mixin');
|
||||
|
||||
assertEquals(TEST_MIXIN.field, block.field);
|
||||
assertEquals(TEST_MIXIN.method, block.method);
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
|
||||
delete Blockly.Extensions.ALL_['mixin_test'];
|
||||
delete Blockly.Blocks['test_block_mixin'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_bad_mixin_overwrites_local_value() {
|
||||
var TEST_MIXIN_BAD_INPUTLIST = {
|
||||
inputList: 'bad inputList' // Defined in constructor
|
||||
};
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['mixin_bad_inputList']);
|
||||
|
||||
// Extension defined before the block type is defined.
|
||||
Blockly.Extensions.registerMixin('mixin_bad_inputList', TEST_MIXIN_BAD_INPUTLIST);
|
||||
assert(goog.isFunction(Blockly.Extensions.ALL_['mixin_bad_inputList']));
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "test_block_bad_inputList",
|
||||
"message0": "test_block_bad_inputList",
|
||||
"extensions": ["mixin_bad_inputList"]
|
||||
}]);
|
||||
|
||||
try {
|
||||
block = new Blockly.Block(workspace, 'test_block_bad_inputList');
|
||||
} catch (e) {
|
||||
// Expected Error
|
||||
assert(e.message.indexOf('inputList') >= 0); // Reference the conflict
|
||||
return;
|
||||
}
|
||||
fail('Expected error when constructing block');
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
|
||||
delete Blockly.Extensions.ALL_['mixin_bad_inputList'];
|
||||
delete Blockly.Blocks['test_block_bad_inputList'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_bad_mixin_overwrites_prototype() {
|
||||
var TEST_MIXIN_BAD_COLOUR = {
|
||||
colour_: 'bad colour_' // Defined on prototype
|
||||
};
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
assertUndefined(Blockly.Extensions.ALL_['mixin_bad_colour_']);
|
||||
|
||||
// Extension defined before the block type is defined.
|
||||
Blockly.Extensions.registerMixin('mixin_bad_colour_', TEST_MIXIN_BAD_COLOUR);
|
||||
assert(goog.isFunction(Blockly.Extensions.ALL_['mixin_bad_colour_']));
|
||||
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "test_block_bad_colour",
|
||||
"message0": "test_block_bad_colour",
|
||||
"extensions": ["mixin_bad_colour_"]
|
||||
}]);
|
||||
|
||||
try {
|
||||
block = new Blockly.Block(workspace, 'test_block_bad_colour');
|
||||
} catch (e) {
|
||||
// Expected Error
|
||||
assert(e.message.indexOf('colour_') >= 0); // Reference the conflict
|
||||
return;
|
||||
}
|
||||
fail('Expected error when constructing block');
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
|
||||
delete Blockly.Extensions.ALL_['mixin_bad_colour_'];
|
||||
delete Blockly.Blocks['test_block_bad_colour'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_mutator_mixin() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"mutator": "mutator_test"
|
||||
}]);
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
Blockly.Events.disable();
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
},
|
||||
compose: function() {
|
||||
return 'composeFn';
|
||||
},
|
||||
decompose: function() {
|
||||
return 'decomposeFn';
|
||||
}
|
||||
});
|
||||
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
|
||||
// Make sure all of the functions were installed correctly.
|
||||
assertEquals(block.domToMutation(), 'domToMutationFn');
|
||||
assertEquals(block.mutationToDom(), 'mutationToDomFn');
|
||||
assertEquals(block.compose(), 'composeFn');
|
||||
assertEquals(block.decompose(), 'decomposeFn');
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_mutator_mixin_no_dialog() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"mutator": "mutator_test"
|
||||
}]);
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
Blockly.Events.disable();
|
||||
assertUndefined(Blockly.Extensions.ALL_['mutator_test']);
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
}
|
||||
});
|
||||
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
|
||||
// Make sure all of the functions were installed correctly.
|
||||
assertEquals(block.domToMutation(), 'domToMutationFn');
|
||||
assertEquals(block.mutationToDom(), 'mutationToDomFn');
|
||||
assertFalse(block.hasOwnProperty('compose'));
|
||||
assertFalse(block.hasOwnProperty('decompose'));
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
}
|
||||
|
||||
// Explicitly check all four things that could be missing.
|
||||
function test_mutator_mixin_no_decompose_fails() {
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
},
|
||||
compose: function() {
|
||||
return 'composeFn';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_mutator_mixin_no_compose_fails() {
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
},
|
||||
decompose: function() {
|
||||
return 'decomposeFn';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_mutator_mixin_no_domToMutation_fails() {
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
},
|
||||
compose: function() {
|
||||
return 'composeFn';
|
||||
},
|
||||
decompose: function() {
|
||||
return 'decomposeFn';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_mutator_mixin_no_mutationToDom_fails() {
|
||||
var exceptionWasThrown = false;
|
||||
try {
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
compose: function() {
|
||||
return 'composeFn';
|
||||
},
|
||||
decompose: function() {
|
||||
return 'decomposeFn';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Expected.
|
||||
exceptionWasThrown = true;
|
||||
} finally {
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_use_mutator_as_extension_fails() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
var exceptionWasThrown = false;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"extensions": ["mutator_test"]
|
||||
}]);
|
||||
|
||||
Blockly.Events.disable();
|
||||
assertUndefined(Blockly.Extensions.ALL_['mutator_test']);
|
||||
Blockly.Extensions.registerMutator('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
}
|
||||
});
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
} catch (e) {
|
||||
// Expected
|
||||
exceptionWasThrown = true;
|
||||
// Should have failed on apply, not on register.
|
||||
assertNotNull(Blockly.Extensions.ALL_['mutator_test']);
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_use_mutator_mixin_as_extension_fails() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
var exceptionWasThrown = false;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"extensions": ["mutator_test"]
|
||||
}]);
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
Blockly.Events.disable();
|
||||
assertUndefined(Blockly.Extensions.ALL_['mutator_test']);
|
||||
Blockly.Extensions.registerMixin('mutator_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
}
|
||||
});
|
||||
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
} catch (e) {
|
||||
// Expected
|
||||
exceptionWasThrown = true;
|
||||
// Should have failed on apply, not on register.
|
||||
assertNotNull(Blockly.Extensions.ALL_['mutator_test']);
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['mutator_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_use_extension_as_mutator_fails() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
var exceptionWasThrown = false;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"mutator": ["extensions_test"]
|
||||
}]);
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
Blockly.Events.disable();
|
||||
assertUndefined(Blockly.Extensions.ALL_['extensions_test']);
|
||||
Blockly.Extensions.register('extensions_test', function() {
|
||||
return 'extensions_test_fn';
|
||||
});
|
||||
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
} catch (e) {
|
||||
// Expected
|
||||
exceptionWasThrown = true;
|
||||
// Should have failed on apply, not on register.
|
||||
assertNotNull(Blockly.Extensions.ALL_['extensions_test']);
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['extensions_test'];
|
||||
}
|
||||
assertTrue(exceptionWasThrown);
|
||||
}
|
||||
|
||||
function test_mutator_mixin_plus_function() {
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
var fnWasCalled = false;
|
||||
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "mutator_test_block",
|
||||
"message0": "mutator_test_block",
|
||||
"mutator": ["extensions_test"]
|
||||
}]);
|
||||
|
||||
Blockly.Events.disable();
|
||||
assertUndefined(Blockly.Extensions.ALL_['extensions_test']);
|
||||
Blockly.Extensions.registerMutator('extensions_test',
|
||||
{
|
||||
domToMutation: function() {
|
||||
return 'domToMutationFn';
|
||||
},
|
||||
mutationToDom: function() {
|
||||
return 'mutationToDomFn';
|
||||
}
|
||||
},
|
||||
function() {
|
||||
fnWasCalled = true;
|
||||
}
|
||||
);
|
||||
|
||||
// Events code calls mutationToDom and expects it to give back a meaningful
|
||||
// value.
|
||||
block = new Blockly.Block(workspace, 'mutator_test_block');
|
||||
} finally {
|
||||
if (block) {
|
||||
block.dispose();
|
||||
}
|
||||
workspace.dispose();
|
||||
Blockly.Events.enable();
|
||||
delete Blockly.Extensions.ALL_['extensions_test'];
|
||||
}
|
||||
assertTrue(fnWasCalled);
|
||||
}
|
||||
44
node_modules/node-blockly/blockly/tests/jsunit/field_angle_test.js
generated
vendored
Normal file
44
node_modules/node-blockly/blockly/tests/jsunit/field_angle_test.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.FieldAngle
|
||||
* @author Anm@anm.me (Andrew n marshall)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_fieldangle_constructor() {
|
||||
assertEquals(new Blockly.FieldAngle().getValue(), '0');
|
||||
assertEquals(new Blockly.FieldAngle(null).getValue(), '0');
|
||||
assertEquals(new Blockly.FieldAngle(undefined).getValue(), '0');
|
||||
assertEquals(new Blockly.FieldAngle(1).getValue(), '1');
|
||||
assertEquals(new Blockly.FieldAngle(1.5).getValue(), '1.5');
|
||||
assertEquals(new Blockly.FieldAngle('2').getValue(), '2');
|
||||
assertEquals(new Blockly.FieldAngle('2.5').getValue(), '2.5');
|
||||
|
||||
// Bad values
|
||||
assertEquals(new Blockly.FieldAngle('bad').getValue(), '0');
|
||||
assertEquals(new Blockly.FieldAngle(NaN).getValue(), '0');
|
||||
}
|
||||
|
||||
function test_fieldangle_fromJson() {
|
||||
assertEquals(Blockly.FieldAngle.fromJson({}).getValue(), '0');
|
||||
assertEquals(Blockly.FieldAngle.fromJson({ angle: 1 }).getValue(), '1');
|
||||
}
|
||||
80
node_modules/node-blockly/blockly/tests/jsunit/field_number_test.js
generated
vendored
Normal file
80
node_modules/node-blockly/blockly/tests/jsunit/field_number_test.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.FieldNumber
|
||||
* @author Anm@anm.me (Andrew n marshall)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_fieldnumber_constructor() {
|
||||
// No arguments
|
||||
var field = new Blockly.FieldNumber();
|
||||
assertEquals(field.getValue(), '0');
|
||||
assertEquals(field.min_, -Infinity);
|
||||
assertEquals(field.max_, Infinity);
|
||||
assertEquals(field.precision_, 0);
|
||||
|
||||
// Numeric values
|
||||
field = new Blockly.FieldNumber(1);
|
||||
assertEquals(field.getValue(), '1');
|
||||
field = new Blockly.FieldNumber(1.5);
|
||||
assertEquals(field.getValue(), '1.5');
|
||||
|
||||
// String value
|
||||
field = new Blockly.FieldNumber('2');
|
||||
assertEquals(field.getValue(), '2');
|
||||
field = new Blockly.FieldNumber('2.5');
|
||||
assertEquals(field.getValue(), '2.5');
|
||||
|
||||
// All values
|
||||
field = new Blockly.FieldNumber(
|
||||
/* value */ 0,
|
||||
/* min */ -128,
|
||||
/* max */ 127,
|
||||
/* precision */ 1);
|
||||
assertEquals(field.getValue(), '0');
|
||||
assertEquals(field.min_, -128);
|
||||
assertEquals(field.max_, 127);
|
||||
assertEquals(field.precision_, 1);
|
||||
|
||||
// Bad value defaults to '0'
|
||||
field = new Blockly.FieldNumber('bad');
|
||||
assertEquals(field.getValue(), '0');
|
||||
field = new Blockly.FieldNumber(NaN);
|
||||
assertEquals(field.getValue(), '0');
|
||||
}
|
||||
|
||||
function test_fieldnumber_fromJson() {
|
||||
assertEquals(Blockly.FieldNumber.fromJson({}).getValue(), '0');
|
||||
assertEquals(Blockly.FieldNumber.fromJson({ value: 1 }).getValue(), '1');
|
||||
|
||||
// All options
|
||||
var field = Blockly.FieldNumber.fromJson({
|
||||
value: 0,
|
||||
min: -128,
|
||||
max: 127,
|
||||
precision: 1
|
||||
});
|
||||
assertEquals(field.getValue(), '0');
|
||||
assertEquals(field.min_, -128);
|
||||
assertEquals(field.max_, 127);
|
||||
assertEquals(field.precision_, 1);
|
||||
}
|
||||
126
node_modules/node-blockly/blockly/tests/jsunit/field_test.js
generated
vendored
Normal file
126
node_modules/node-blockly/blockly/tests/jsunit/field_test.js
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.Field
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_field_isEditable_simple() {
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
// EDITABLE is true by default, but without a source block a field can't be
|
||||
// edited.
|
||||
assertFalse('Field without a block is not editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_isEditable_false() {
|
||||
// Setting EDITABLE to false doesn't matter.
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
field.EDITABLE = false;
|
||||
assertFalse('Field without a block is not editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_isEditable_editableBlock() {
|
||||
var editableBlock = {
|
||||
isEditable: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
field.sourceBlock_ = editableBlock;
|
||||
|
||||
assertTrue('Editable field with editable block is editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_isEditable_editableBlock_false() {
|
||||
var editableBlock = {
|
||||
isEditable: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
field.sourceBlock_ = editableBlock;
|
||||
field.EDITABLE = false;
|
||||
|
||||
assertFalse('Non-editable field with editable block is not editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_isEditable_nonEditableBlock() {
|
||||
var nonEditableBlock = {
|
||||
isEditable: function() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
field.sourceBlock_ = nonEditableBlock;
|
||||
|
||||
assertFalse('Editable field with non-editable block is not editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_isEditable_nonEditableBlock_false() {
|
||||
var nonEditableBlock = {
|
||||
isEditable: function() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var field = new Blockly.Field("Dummy text");
|
||||
field.sourceBlock_ = nonEditableBlock;
|
||||
field.EDITABLE = false;
|
||||
|
||||
assertFalse('Non-editable field with non-editable block is not editable',
|
||||
field.isCurrentlyEditable());
|
||||
}
|
||||
|
||||
function test_field_register_with_custom_field() {
|
||||
var CustomFieldType = function(value) {
|
||||
CustomFieldType.superClass_.constructor.call(this, value);
|
||||
};
|
||||
goog.inherits(CustomFieldType, Blockly.Field);
|
||||
|
||||
CustomFieldType.fromJson = function(options) {
|
||||
return new CustomFieldType(options['value']);
|
||||
};
|
||||
|
||||
var json = {
|
||||
type: 'field_custom_test',
|
||||
value: 'ok'
|
||||
};
|
||||
|
||||
// before registering
|
||||
var field = Blockly.Field.fromJson(json);
|
||||
assertNull(field);
|
||||
|
||||
Blockly.Field.register('field_custom_test', CustomFieldType);
|
||||
|
||||
// after registering
|
||||
field = Blockly.Field.fromJson(json);
|
||||
assertNotNull(field);
|
||||
assertEquals(field.getValue(), 'ok');
|
||||
}
|
||||
237
node_modules/node-blockly/blockly/tests/jsunit/field_variable_test.js
generated
vendored
Normal file
237
node_modules/node-blockly/blockly/tests/jsunit/field_variable_test.js
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.FieldVariable
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
var workspace;
|
||||
var mockControl_;
|
||||
|
||||
function fieldVariableTestWithMocks_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
}
|
||||
|
||||
function fieldVariableTestWithMocks_tearDown() {
|
||||
mockControl_.$tearDown();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function fieldVariable_mockBlock(workspace) {
|
||||
return {'workspace': workspace, 'isShadow': function(){return false;}};
|
||||
}
|
||||
|
||||
function fieldVariable_createAndInitField(workspace) {
|
||||
var fieldVariable = new Blockly.FieldVariable('name1');
|
||||
var mockBlock = fieldVariable_mockBlock(workspace);
|
||||
fieldVariable.setSourceBlock(mockBlock);
|
||||
// No view to initialize, but the model still needs work.
|
||||
fieldVariable.initModel();
|
||||
return fieldVariable;
|
||||
}
|
||||
|
||||
function test_fieldVariable_Constructor() {
|
||||
workspace = new Blockly.Workspace();
|
||||
var fieldVariable = new Blockly.FieldVariable('name1');
|
||||
// The field does not have a variable until after init() is called.
|
||||
assertEquals('', fieldVariable.getText());
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_fieldVariable_setValueMatchId() {
|
||||
// Expect the fieldVariable value to be set to variable name
|
||||
fieldVariableTestWithMocks_setUp();
|
||||
workspace.createVariable('name2', null, 'id2');
|
||||
|
||||
var fieldVariable = fieldVariable_createAndInitField(workspace);
|
||||
|
||||
var oldId = fieldVariable.getValue();
|
||||
var event = new Blockly.Events.BlockChange(
|
||||
fieldVariable.sourceBlock_, 'field', undefined, oldId, 'id2');
|
||||
setUpMockMethod(mockControl_, Blockly.Events, 'fire', [event], null);
|
||||
|
||||
fieldVariable.setValue('id2');
|
||||
assertEquals('name2', fieldVariable.getText());
|
||||
assertEquals('id2', fieldVariable.getValue());
|
||||
fieldVariableTestWithMocks_tearDown();
|
||||
}
|
||||
|
||||
function test_fieldVariable_setValueNoVariable() {
|
||||
fieldVariableTestWithMocks_setUp();
|
||||
|
||||
var fieldVariable = fieldVariable_createAndInitField(workspace);
|
||||
var mockBlock = fieldVariable.sourceBlock_;
|
||||
mockBlock.isShadow = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
try {
|
||||
fieldVariable.setValue('id1');
|
||||
// Calling setValue with a variable that doesn't exist throws an error.
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
} finally {
|
||||
fieldVariableTestWithMocks_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_fieldVariable_dropdownCreateVariablesExist() {
|
||||
// Expect that the dropdown options will contain the variables that exist.
|
||||
workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
workspace.createVariable('name2', '', 'id2');
|
||||
|
||||
var fieldVariable = fieldVariable_createAndInitField(workspace);
|
||||
|
||||
var result_options = Blockly.FieldVariable.dropdownCreate.call(
|
||||
fieldVariable);
|
||||
|
||||
assertEquals(result_options.length, 3);
|
||||
isEqualArrays(result_options[0], ['name1', 'id1']);
|
||||
isEqualArrays(result_options[1], ['name2', 'id2']);
|
||||
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_fieldVariable_setValueNull() {
|
||||
// This should no longer create a variable for the selected option.
|
||||
fieldVariableTestWithMocks_setUp();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['id1', null]);
|
||||
|
||||
var fieldVariable = fieldVariable_createAndInitField(workspace);
|
||||
try {
|
||||
fieldVariable.setValue(null);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
} finally {
|
||||
fieldVariableTestWithMocks_tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function test_fieldVariable_getVariableTypes_undefinedVariableTypes() {
|
||||
// Expect that since variableTypes is undefined, only type empty string
|
||||
// will be returned (regardless of what types are available on the workspace).
|
||||
workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('name1', 'type1');
|
||||
workspace.createVariable('name2', 'type2');
|
||||
|
||||
var fieldVariable = new Blockly.FieldVariable('name1');
|
||||
var resultTypes = fieldVariable.getVariableTypes_();
|
||||
isEqualArrays(resultTypes, ['']);
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_fieldVariable_getVariableTypes_givenVariableTypes() {
|
||||
// Expect that since variableTypes is defined, it will be the return value,
|
||||
// regardless of what types are available on the workspace.
|
||||
workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('name1', 'type1');
|
||||
workspace.createVariable('name2', 'type2');
|
||||
|
||||
var fieldVariable = new Blockly.FieldVariable(
|
||||
'name1', null, ['type1', 'type2'], 'type1');
|
||||
var resultTypes = fieldVariable.getVariableTypes_();
|
||||
isEqualArrays(resultTypes, ['type1', 'type2']);
|
||||
assertEquals('Default type was wrong', 'type1', fieldVariable.defaultType_);
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_fieldVariable_getVariableTypes_nullVariableTypes() {
|
||||
// Expect all variable types to be returned.
|
||||
// The variable does not need to be initialized to do this--it just needs a
|
||||
// pointer to the workspace.
|
||||
workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('name1', 'type1');
|
||||
workspace.createVariable('name2', 'type2');
|
||||
|
||||
var fieldVariable = new Blockly.FieldVariable('name1');
|
||||
var mockBlock = fieldVariable_mockBlock(workspace);
|
||||
fieldVariable.setSourceBlock(mockBlock);
|
||||
fieldVariable.variableTypes = null;
|
||||
|
||||
var resultTypes = fieldVariable.getVariableTypes_();
|
||||
// The empty string is always one of the options.
|
||||
isEqualArrays(resultTypes, ['type1', 'type2', '']);
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_fieldVariable_getVariableTypes_emptyListVariableTypes() {
|
||||
// Expect an error to be thrown.
|
||||
workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('name1', 'type1');
|
||||
workspace.createVariable('name2', 'type2');
|
||||
|
||||
var fieldVariable = new Blockly.FieldVariable('name1');
|
||||
var mockBlock = fieldVariable_mockBlock(workspace);
|
||||
fieldVariable.setSourceBlock(mockBlock);
|
||||
fieldVariable.variableTypes = [];
|
||||
|
||||
try {
|
||||
fieldVariable.getVariableTypes_();
|
||||
fail();
|
||||
} catch (e) {
|
||||
//expected
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_fieldVariable_defaultType_exists() {
|
||||
var fieldVariable = new Blockly.FieldVariable(null, null, ['b'], 'b');
|
||||
assertEquals('The variable field\'s default type should be "b"',
|
||||
'b', fieldVariable.defaultType_);
|
||||
}
|
||||
|
||||
function test_fieldVariable_noDefaultType() {
|
||||
var fieldVariable = new Blockly.FieldVariable(null);
|
||||
assertEquals('The variable field\'s default type should be the empty string',
|
||||
'', fieldVariable.defaultType_);
|
||||
assertNull('The variable field\'s allowed types should be null',
|
||||
fieldVariable.variableTypes);
|
||||
}
|
||||
|
||||
function test_fieldVariable_defaultTypeMismatch() {
|
||||
try {
|
||||
var fieldVariable = new Blockly.FieldVariable(null, null, ['a'], 'b');
|
||||
fail('Variable field creation should have failed due to an invalid ' +
|
||||
'default type');
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
function test_fieldVariable_defaultTypeMismatch_empty() {
|
||||
try {
|
||||
var fieldVariable = new Blockly.FieldVariable(null, null, ['a']);
|
||||
fail('Variable field creation should have failed due to an invalid ' +
|
||||
'default type');
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
28
node_modules/node-blockly/blockly/tests/jsunit/generator_test.js
generated
vendored
Normal file
28
node_modules/node-blockly/blockly/tests/jsunit/generator_test.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_prefix() {
|
||||
var generator = new Blockly.Generator('INTERCAL');
|
||||
assertEquals('Prefix nothing.', '', generator.prefixLines('', ''));
|
||||
assertEquals('Prefix a word.', '@Hello', generator.prefixLines('Hello', '@'));
|
||||
assertEquals('Prefix one line.', '12Hello\n', generator.prefixLines('Hello\n', '12'));
|
||||
assertEquals('Prefix two lines.', '***Hello\n***World\n', generator.prefixLines('Hello\nWorld\n', '***'));
|
||||
}
|
||||
90
node_modules/node-blockly/blockly/tests/jsunit/gesture_test.js
generated
vendored
Normal file
90
node_modules/node-blockly/blockly/tests/jsunit/gesture_test.js
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for gesture.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var e;
|
||||
var workspace;
|
||||
|
||||
|
||||
function gestureTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
e = {};
|
||||
}
|
||||
|
||||
function gestureTest_tearDown() {
|
||||
e = null;
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_gestureConstructor() {
|
||||
var gesture = new Blockly.Gesture(e, workspace);
|
||||
assertEquals(gesture.mostRecentEvent_, e);
|
||||
assertEquals(gesture.creatorWorkspace_, workspace);
|
||||
}
|
||||
|
||||
function test_gestureIsField_ClickInWorkspace() {
|
||||
gestureTest_setUp();
|
||||
var block = new Blockly.Block(workspace);
|
||||
var field = new Blockly.Field();
|
||||
field.setSourceBlock(block);
|
||||
var gesture = new Blockly.Gesture(e, workspace);
|
||||
gesture.setStartField(field);
|
||||
|
||||
var isFieldClick = gesture.isFieldClick_();
|
||||
assertEquals(isFieldClick, true);
|
||||
gestureTest_tearDown();
|
||||
}
|
||||
|
||||
function gestureIsFieldClick_InFlyoutHelper(flyout, expectedResult){
|
||||
// Assign workspace flyout
|
||||
workspace.flyout_ = flyout;
|
||||
// Create a Field inside of a Block
|
||||
var block = new Blockly.Block(workspace);
|
||||
var field = new Blockly.Field();
|
||||
field.setSourceBlock(block);
|
||||
// Create gesture from the flyout
|
||||
var gesture = new Blockly.Gesture(e, workspace.flyout_);
|
||||
// Populate gesture with click start information
|
||||
gesture.setStartField(field);
|
||||
gesture.setStartFlyout_(workspace.flyout_);
|
||||
|
||||
var isFieldClick = gesture.isFieldClick_();
|
||||
assertEquals(isFieldClick, expectedResult);
|
||||
}
|
||||
|
||||
function test_gestureIsFieldClick_AutoCloseFlyout() {
|
||||
gestureTest_setUp();
|
||||
var flyout = new Blockly.VerticalFlyout({});
|
||||
gestureIsFieldClick_InFlyoutHelper(flyout, false);
|
||||
gestureTest_tearDown();
|
||||
}
|
||||
|
||||
function test_gestureIsFieldClick_AlwaysOpenFlyout() {
|
||||
gestureTest_setUp();
|
||||
var flyout = new Blockly.VerticalFlyout({});
|
||||
flyout.autoClose = false;
|
||||
gestureIsFieldClick_InFlyoutHelper(flyout, true);
|
||||
gestureTest_tearDown();
|
||||
}
|
||||
35
node_modules/node-blockly/blockly/tests/jsunit/index.html
generated
vendored
Normal file
35
node_modules/node-blockly/blockly/tests/jsunit/index.html
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Unit Tests for Blockly</title>
|
||||
<script src="../../blockly_uncompressed.js"></script>
|
||||
<script>goog.require('goog.testing.jsunit');</script>
|
||||
</head>
|
||||
<body>
|
||||
<script src="test_utilities.js"></script>
|
||||
<script src="connection_db_test.js"></script>
|
||||
<script src="connection_test.js"></script>
|
||||
<script src="event_test.js"></script>
|
||||
<script src="extensions_test.js"></script>
|
||||
<script src="field_angle_test.js"></script>
|
||||
<script src="field_number_test.js"></script>
|
||||
<script src="field_test.js"></script>
|
||||
<script src="field_variable_test.js"></script>
|
||||
<script src="generator_test.js"></script>
|
||||
<script src="gesture_test.js"></script>
|
||||
<script src="input_test.js"></script>
|
||||
<script src="json_test.js"></script>
|
||||
<script src="metrics_test.js"></script>
|
||||
<script src="names_test.js"></script>
|
||||
<script src="procedures_test.js"></script>
|
||||
<script src="utils_test.js"></script>
|
||||
<script src="variables_test.js"></script>
|
||||
<script src="variable_map_test.js"></script>
|
||||
<script src="variable_model_test.js"></script>
|
||||
<script src="widget_div_test.js"></script>
|
||||
<script src="workspace_test.js"></script>
|
||||
<script src="workspace_undo_redo_test.js"></script>
|
||||
<script src="xml_test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
202
node_modules/node-blockly/blockly/tests/jsunit/input_test.js
generated
vendored
Normal file
202
node_modules/node-blockly/blockly/tests/jsunit/input_test.js
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.Input
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_appendField_simple() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var field1 = new Blockly.FieldLabel('#1');
|
||||
var field2 = new Blockly.FieldLabel('#2');
|
||||
|
||||
// Preconditions
|
||||
assertEquals(0, input.fieldRow.length);
|
||||
|
||||
// Actual Tests
|
||||
input.appendField(field1, 'first');
|
||||
assertEquals(1, input.fieldRow.length);
|
||||
assertEquals(field1, input.fieldRow[0]);
|
||||
assertEquals('first', input.fieldRow[0].name);
|
||||
assertEquals(block, field1.sourceBlock_);
|
||||
|
||||
input.appendField(field2, 'second');
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(field2, input.fieldRow[1]);
|
||||
assertEquals('second', input.fieldRow[1].name);
|
||||
assertEquals(block, field2.sourceBlock_);
|
||||
}
|
||||
|
||||
function test_appendField_string() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var labelText = 'label';
|
||||
|
||||
// Preconditions
|
||||
assertEquals(0, input.fieldRow.length);
|
||||
|
||||
// Actual Tests
|
||||
input.appendField(labelText, 'name');
|
||||
assertEquals(1, input.fieldRow.length);
|
||||
assertEquals(Blockly.FieldLabel, input.fieldRow[0].constructor);
|
||||
assertEquals(labelText, input.fieldRow[0].getValue());
|
||||
assertEquals('name', input.fieldRow[0].name);
|
||||
}
|
||||
|
||||
function test_appendField_prefix() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var prefix = new Blockly.FieldLabel('prefix');
|
||||
var field = new Blockly.FieldLabel('field');
|
||||
field.prefixField = prefix;
|
||||
|
||||
// Preconditions
|
||||
assertEquals(0, input.fieldRow.length);
|
||||
|
||||
// Actual Tests
|
||||
input.appendField(field);
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(prefix, input.fieldRow[0]);
|
||||
assertEquals(field, input.fieldRow[1]);
|
||||
}
|
||||
|
||||
function test_appendField_suffix() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var suffix = new Blockly.FieldLabel('suffix');
|
||||
var field = new Blockly.FieldLabel('field');
|
||||
field.suffixField = suffix;
|
||||
|
||||
// Preconditions
|
||||
assertEquals(0, input.fieldRow.length);
|
||||
|
||||
// Actual Tests
|
||||
input.appendField(field);
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(field, input.fieldRow[0]);
|
||||
assertEquals(suffix, input.fieldRow[1]);
|
||||
}
|
||||
|
||||
function test_insertFieldAt_simple() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var before = new Blockly.FieldLabel('before');
|
||||
var after = new Blockly.FieldLabel('after');
|
||||
var between = new Blockly.FieldLabel('between');
|
||||
input.appendField(before);
|
||||
input.appendField(after);
|
||||
|
||||
// Preconditions
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(after, input.fieldRow[1]);
|
||||
|
||||
// Actual Tests
|
||||
input.insertFieldAt(1, between, 'name');
|
||||
assertEquals(3, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(between, input.fieldRow[1]);
|
||||
assertEquals('name', input.fieldRow[1].name);
|
||||
assertEquals(after, input.fieldRow[2]);
|
||||
}
|
||||
|
||||
function test_insertFieldAt_string() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var before = new Blockly.FieldLabel('before');
|
||||
var after = new Blockly.FieldLabel('after');
|
||||
var labelText = 'label';
|
||||
input.appendField(before);
|
||||
input.appendField(after);
|
||||
|
||||
// Preconditions
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(after, input.fieldRow[1]);
|
||||
|
||||
// Actual Tests
|
||||
input.insertFieldAt(1, labelText, 'name');
|
||||
assertEquals(3, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(Blockly.FieldLabel, input.fieldRow[1].constructor);
|
||||
assertEquals(labelText, input.fieldRow[1].getValue());
|
||||
assertEquals('name', input.fieldRow[1].name);
|
||||
assertEquals(after, input.fieldRow[2]);
|
||||
}
|
||||
|
||||
function test_insertFieldAt_prefix() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var before = new Blockly.FieldLabel('before');
|
||||
var after = new Blockly.FieldLabel('after');
|
||||
var prefix = new Blockly.FieldLabel('prefix');
|
||||
var between = new Blockly.FieldLabel('between');
|
||||
between.prefixField = prefix;
|
||||
input.appendField(before);
|
||||
input.appendField(after);
|
||||
|
||||
// Preconditions
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(after, input.fieldRow[1]);
|
||||
|
||||
// Actual Tests
|
||||
input.insertFieldAt(1, between);
|
||||
assertEquals(4, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(prefix, input.fieldRow[1]);
|
||||
assertEquals(between, input.fieldRow[2]);
|
||||
assertEquals(after, input.fieldRow[3]);
|
||||
}
|
||||
|
||||
function test_insertFieldAt_suffix() {
|
||||
var ws = new Blockly.Workspace();
|
||||
var block = new Blockly.Block(ws);
|
||||
var input = new Blockly.Input(Blockly.DUMMY_INPUT, 'INPUT', block);
|
||||
var before = new Blockly.FieldLabel('before');
|
||||
var after = new Blockly.FieldLabel('after');
|
||||
var suffix = new Blockly.FieldLabel('suffix');
|
||||
var between = new Blockly.FieldLabel('between');
|
||||
between.suffixField = suffix;
|
||||
input.appendField(before);
|
||||
input.appendField(after);
|
||||
|
||||
// Preconditions
|
||||
assertEquals(2, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(after, input.fieldRow[1]);
|
||||
|
||||
// Actual Tests
|
||||
input.insertFieldAt(1, between);
|
||||
assertEquals(4, input.fieldRow.length);
|
||||
assertEquals(before, input.fieldRow[0]);
|
||||
assertEquals(between, input.fieldRow[1]);
|
||||
assertEquals(suffix, input.fieldRow[2]);
|
||||
assertEquals(after, input.fieldRow[3]);
|
||||
}
|
||||
370
node_modules/node-blockly/blockly/tests/jsunit/json_test.js
generated
vendored
Normal file
370
node_modules/node-blockly/blockly/tests/jsunit/json_test.js
generated
vendored
Normal file
@@ -0,0 +1,370 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/** Ensure a block can be instantiated from a JSON definition. */
|
||||
function test_json_minimal() {
|
||||
var BLOCK_TYPE = 'test_json_minimal';
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
var warnings = captureWarnings(function() {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE
|
||||
}]);
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
});
|
||||
|
||||
assertEquals(BLOCK_TYPE, block.type);
|
||||
assertEquals(
|
||||
'Expecting no warnings when defining and creating a simple block.',
|
||||
warnings.length, 0);
|
||||
// TODO: asserts
|
||||
} finally {
|
||||
block.dispose();
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a block without a type id fails with a warning, but does not block
|
||||
* later definitions.
|
||||
*/
|
||||
function test_json_nullOrUndefinedBlockTypeId() {
|
||||
var BLOCK_TYPE1 = 'test_json_before_bad_blocks';
|
||||
var BLOCK_TYPE2 = 'test_json_after_bad_blocks';
|
||||
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
var blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
|
||||
try {
|
||||
var warnings = captureWarnings(function() {
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{"type": BLOCK_TYPE1},
|
||||
{"type": undefined},
|
||||
{"type": null},
|
||||
{"type": BLOCK_TYPE2}]);
|
||||
});
|
||||
|
||||
assertNotNullNorUndefined('Block before bad blocks should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertNotNullNorUndefined('Block after bad blocks should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assertEquals(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assertEquals(
|
||||
'Expecting 2 warnings, one for each bad block.', warnings.length, 2);
|
||||
} finally {
|
||||
delete Blockly.Blocks[BLOCK_TYPE1];
|
||||
delete Blockly.Blocks[BLOCK_TYPE2];
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure message0 creates an input. */
|
||||
function test_json_message0() {
|
||||
var BLOCK_TYPE = 'test_json_message0';
|
||||
var MESSAGE0 = 'message0';
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE,
|
||||
"message0": MESSAGE0
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
assertEquals(1, block.inputList.length);
|
||||
assertEquals(1, block.inputList[0].fieldRow.length);
|
||||
var textField = block.inputList[0].fieldRow[0];
|
||||
assertEquals(Blockly.FieldLabel, textField.constructor);
|
||||
assertEquals(MESSAGE0, textField.getText());
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure message1 creates a new input. */
|
||||
function test_json_message1() {
|
||||
var BLOCK_TYPE = 'test_json_message1';
|
||||
var MESSAGE0 = 'message0';
|
||||
var MESSAGE1 = 'message1';
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE,
|
||||
"message0": MESSAGE0,
|
||||
"message1": MESSAGE1
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
assertEquals(2, block.inputList.length);
|
||||
|
||||
assertEquals(1, block.inputList[0].fieldRow.length);
|
||||
var textField = block.inputList[0].fieldRow[0];
|
||||
assertEquals(Blockly.FieldLabel, textField.constructor);
|
||||
assertEquals(MESSAGE0, textField.getText());
|
||||
|
||||
assertEquals(1, block.inputList[1].fieldRow.length);
|
||||
var textField = block.inputList[1].fieldRow[0];
|
||||
assertEquals(Blockly.FieldLabel, textField.constructor);
|
||||
assertEquals(MESSAGE1, textField.getText());
|
||||
} finally {
|
||||
block && block.dispose();
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure message string is dereferenced. */
|
||||
function test_json_message0_i18n() {
|
||||
var BLOCK_TYPE = 'test_json_message0_i18n';
|
||||
var MESSAGE0 = '%{BKY_MESSAGE}';
|
||||
var MESSAGE = 'message';
|
||||
|
||||
Blockly.Msg['MESSAGE'] = MESSAGE;
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE,
|
||||
"message0": MESSAGE0
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
assertEquals(1, block.inputList.length);
|
||||
assertEquals(1, block.inputList[0].fieldRow.length);
|
||||
var textField = block.inputList[0].fieldRow[0];
|
||||
assertEquals(Blockly.FieldLabel, textField.constructor);
|
||||
assertEquals(MESSAGE, textField.getText());
|
||||
} finally {
|
||||
block && block.dispose(); // Disposes of textField, too.
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
delete Blockly.Msg['MESSAGE'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_json_dropdown() {
|
||||
var BLOCK_TYPE = 'test_json_dropdown';
|
||||
var FIELD_NAME = 'FIELD_NAME';
|
||||
var LABEL0 = 'LABEL0';
|
||||
var VALUE0 = 'VALUE0';
|
||||
var LABEL1 = 'LABEL1';
|
||||
var VALUE1 = 'VALUE1';
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE,
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": FIELD_NAME,
|
||||
"options": [
|
||||
[LABEL0, VALUE0],
|
||||
[LABEL1, VALUE1]
|
||||
]
|
||||
}
|
||||
]
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
assertEquals(1, block.inputList.length);
|
||||
assertEquals(1, block.inputList[0].fieldRow.length);
|
||||
var dropdown = block.inputList[0].fieldRow[0];
|
||||
assertEquals(dropdown, block.getField(FIELD_NAME));
|
||||
assertEquals(Blockly.FieldDropdown, dropdown.constructor);
|
||||
assertEquals(VALUE0, dropdown.getValue());
|
||||
|
||||
var options = dropdown.getOptions();
|
||||
assertEquals(LABEL0, options[0][0]);
|
||||
assertEquals(VALUE0, options[0][1]);
|
||||
assertEquals(LABEL1, options[1][0]);
|
||||
assertEquals(VALUE1, options[1][1]);
|
||||
} finally {
|
||||
block && block.dispose(); // Disposes of dropdown, too.
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
}
|
||||
}
|
||||
|
||||
function test_json_dropdown_image() {
|
||||
var BLOCK_TYPE = 'test_json_dropdown';
|
||||
var FIELD_NAME = 'FIELD_NAME';
|
||||
var IMAGE1_ALT_TEXT = 'Localized message.';
|
||||
Blockly.Msg['ALT_TEXT'] = IMAGE1_ALT_TEXT;
|
||||
var IMAGE0 = {
|
||||
'width': 12,
|
||||
'height': 34,
|
||||
'src': 'http://image0.src',
|
||||
'alt': 'IMAGE0 alt text'
|
||||
};
|
||||
var VALUE0 = 'VALUE0';
|
||||
var IMAGE1 = {
|
||||
'width': 56,
|
||||
'height': 78,
|
||||
'src': 'http://image1.src',
|
||||
'alt': '%{BKY_ALT_TEXT}'
|
||||
};
|
||||
var VALUE1 = 'VALUE1';
|
||||
var IMAGE2 = {
|
||||
'width': 90,
|
||||
'height': 123,
|
||||
'src': 'http://image2.src'
|
||||
};
|
||||
var VALUE2 = 'VALUE2';
|
||||
|
||||
var workspace = new Blockly.Workspace();
|
||||
var block;
|
||||
try {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": BLOCK_TYPE,
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_dropdown",
|
||||
"name": FIELD_NAME,
|
||||
"options": [
|
||||
[IMAGE0, VALUE0],
|
||||
[IMAGE1, VALUE1],
|
||||
[IMAGE2, VALUE2]
|
||||
]
|
||||
}
|
||||
]
|
||||
}]);
|
||||
|
||||
block = new Blockly.Block(workspace, BLOCK_TYPE);
|
||||
assertEquals(1, block.inputList.length);
|
||||
assertEquals(1, block.inputList[0].fieldRow.length);
|
||||
var dropdown = block.inputList[0].fieldRow[0];
|
||||
assertEquals(dropdown, block.getField(FIELD_NAME));
|
||||
assertEquals(Blockly.FieldDropdown, dropdown.constructor);
|
||||
assertEquals(VALUE0, dropdown.getValue());
|
||||
|
||||
var options = dropdown.getOptions();
|
||||
var image0 = options[0][0];
|
||||
assertEquals(IMAGE0.width, image0.width);
|
||||
assertEquals(IMAGE0.height, image0.height);
|
||||
assertEquals(IMAGE0.src, image0.src);
|
||||
assertEquals(IMAGE0.alt, image0.alt);
|
||||
assertEquals(VALUE0, options[0][1]);
|
||||
|
||||
var image1 = options[1][0];
|
||||
assertEquals(IMAGE1.width, image1.width);
|
||||
assertEquals(IMAGE1.height, image1.height);
|
||||
assertEquals(IMAGE1.src, image1.src);
|
||||
assertEquals(IMAGE1.alt, IMAGE1_ALT_TEXT); // Via Msg reference
|
||||
assertEquals(VALUE1, options[1][1]);
|
||||
|
||||
var image2 = options[2][0];
|
||||
assertEquals(IMAGE2.width, image2.width);
|
||||
assertEquals(IMAGE2.height, image2.height);
|
||||
assertEquals(IMAGE2.src, image2.src);
|
||||
assert(image2.alt == null); // No alt specified.
|
||||
assertEquals(VALUE2, options[2][1]);
|
||||
} finally {
|
||||
block && block.dispose(); // Disposes of dropdown, too.
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE];
|
||||
delete Blockly.Msg['ALTTEXT'];
|
||||
}
|
||||
}
|
||||
|
||||
function test_defineBlocksWithJsonArray_nullItem() {
|
||||
var BLOCK_TYPE1 = 'test_block_before_null';
|
||||
var BLOCK_TYPE2 = 'test_block_after_null';
|
||||
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
var blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
|
||||
try {
|
||||
var warnings = captureWarnings(function() {
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{
|
||||
"type": BLOCK_TYPE1,
|
||||
"message0": 'before'
|
||||
},
|
||||
null,
|
||||
{
|
||||
"type": BLOCK_TYPE2,
|
||||
"message0": 'after'
|
||||
}]);
|
||||
});
|
||||
assertNotNullNorUndefined(
|
||||
'Block before null in array should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertNotNullNorUndefined(
|
||||
'Block after null in array should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assertEquals(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assertEquals('Expected 1 warning for the bad block.', warnings.length, 1);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE1];
|
||||
delete Blockly.Blocks[BLOCK_TYPE2];
|
||||
}
|
||||
}
|
||||
|
||||
function test_defineBlocksWithJsonArray_undefinedItem() {
|
||||
var BLOCK_TYPE1 = 'test_block_before_undefined';
|
||||
var BLOCK_TYPE2 = 'test_block_after_undefined';
|
||||
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertUndefined(Blockly.Blocks[BLOCK_TYPE2]);
|
||||
var blockTypeCount = Object.keys(Blockly.Blocks).length;
|
||||
|
||||
try {
|
||||
var warnings = captureWarnings(function() {
|
||||
Blockly.defineBlocksWithJsonArray([
|
||||
{
|
||||
"type": BLOCK_TYPE1,
|
||||
"message0": 'before'
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
"type": BLOCK_TYPE2,
|
||||
"message0": 'after'
|
||||
}]);
|
||||
});
|
||||
assertNotNullNorUndefined(
|
||||
'Block before undefined in array should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE1]);
|
||||
assertNotNullNorUndefined(
|
||||
'Block after undefined in array should be defined.',
|
||||
Blockly.Blocks[BLOCK_TYPE2]);
|
||||
assertEquals(Object.keys(Blockly.Blocks).length, blockTypeCount + 2);
|
||||
assertEquals('Expected 1 warning for the bad block.', warnings.length, 1);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks[BLOCK_TYPE1];
|
||||
delete Blockly.Blocks[BLOCK_TYPE2];
|
||||
}
|
||||
}
|
||||
132
node_modules/node-blockly/blockly/tests/jsunit/metrics_test.js
generated
vendored
Normal file
132
node_modules/node-blockly/blockly/tests/jsunit/metrics_test.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2018 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function assertDimensionsMatch(toCheck, left, top, width, height) {
|
||||
assertEquals('Top did not match.', top, toCheck.top);
|
||||
assertEquals('Left did not match.', left, toCheck.left);
|
||||
assertEquals('Width did not match.', width, toCheck.width);
|
||||
assertEquals('Height did not match.', height, toCheck.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a mock workspace object with two properties: getBlocksBoundingBox and
|
||||
* scale.
|
||||
*/
|
||||
function makeMockWs(scale, x, y, width, height) {
|
||||
return {
|
||||
getBlocksBoundingBox: function() {
|
||||
return {
|
||||
width: width,
|
||||
height: height,
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
},
|
||||
scale: scale
|
||||
};
|
||||
}
|
||||
|
||||
// Empty workspace.
|
||||
var test_GetContentDimensionsExact_empty = function() {
|
||||
var ws = makeMockWs(1, 0, 0, 0, 0)
|
||||
var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
assertDimensionsMatch(defaultZoom, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_emptyZoomIn = function() {
|
||||
var ws = makeMockWs(2, 0, 0, 0, 0)
|
||||
var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
assertDimensionsMatch(zoomIn, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_emptyZoomOut = function() {
|
||||
var ws = makeMockWs(.5, 0, 0, 0, 0)
|
||||
var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
assertDimensionsMatch(zoomOut, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
// Non-empty workspace, with top-left corner at ws origin.
|
||||
var test_GetContentDimensionsExact_nonEmptyAtOrigin = function() {
|
||||
var ws = makeMockWs(1, 0, 0, 100, 100)
|
||||
var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// Pixel and ws units are the same at default zoom.
|
||||
assertDimensionsMatch(defaultZoom, 0, 0, 100, 100);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_nonEmptyAtOriginZoomIn = function() {
|
||||
var ws = makeMockWs(2, 0, 0, 100, 100)
|
||||
var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 2 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomIn, 0, 0, 200, 200);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_nonEmptyAtOriginZoomOut = function() {
|
||||
var ws = makeMockWs(.5, 0, 0, 100, 100)
|
||||
var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomOut, 0, 0, 50, 50);
|
||||
}
|
||||
|
||||
// Non-empty workspace, with top-left corner in positive ws coordinates.
|
||||
var test_GetContentDimensionsExact_nonEmptyPositiveOrigin = function() {
|
||||
var ws = makeMockWs(1, 10, 10, 100, 100)
|
||||
var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// Pixel and ws units are the same at default zoom.
|
||||
assertDimensionsMatch(defaultZoom, 10, 10, 100, 100);
|
||||
}
|
||||
|
||||
// Changing zoom will change both width/height and origin location in pixels.
|
||||
var test_GetContentDimensionsExact_nonEmptyPositiveOriginZoomIn = function() {
|
||||
var ws = makeMockWs(2, 10, 10, 100, 100)
|
||||
var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 2 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomIn, 20, 20, 200, 200);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_nonEmptyPositiveOriginZoomOut = function() {
|
||||
var ws = makeMockWs(.5, 10, 10, 100, 100)
|
||||
var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomOut, 5, 5, 50, 50);
|
||||
}
|
||||
|
||||
// Non-empty workspace, with top-left corner in negative ws coordinates.
|
||||
var test_GetContentDimensionsExact_nonEmptyNegativeOrigin = function() {
|
||||
var ws = makeMockWs(1, -10, -10, 100, 100)
|
||||
var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// Pixel and ws units are the same at default zoom.
|
||||
assertDimensionsMatch(defaultZoom, -10, -10, 100, 100);
|
||||
}
|
||||
|
||||
// Changing zoom will change both width/height and origin location in pixels.
|
||||
var test_GetContentDimensionsExact_nonEmptyNegativeOriginZoomIn = function() {
|
||||
var ws = makeMockWs(2, -10, -10, 100, 100)
|
||||
var zoomIn = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 2 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomIn, -20, -20, 200, 200);
|
||||
}
|
||||
|
||||
var test_GetContentDimensionsExact_nonEmptyNegativeOriginZoomOut = function() {
|
||||
var ws = makeMockWs(.5, -10, -10, 100, 100)
|
||||
var zoomOut = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
// 1 ws unit = 0.5 pixels at this zoom level.
|
||||
assertDimensionsMatch(zoomOut, -5, -5, 50, 50);
|
||||
}
|
||||
62
node_modules/node-blockly/blockly/tests/jsunit/names_test.js
generated
vendored
Normal file
62
node_modules/node-blockly/blockly/tests/jsunit/names_test.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_safeName() {
|
||||
var varDB = new Blockly.Names('window,door');
|
||||
assertEquals('SafeName empty.', 'unnamed', varDB.safeName_(''));
|
||||
assertEquals('SafeName ok.', 'foobar', varDB.safeName_('foobar'));
|
||||
assertEquals('SafeName number start.', 'my_9lives',
|
||||
varDB.safeName_('9lives'));
|
||||
assertEquals('SafeName number end.', 'lives9', varDB.safeName_('lives9'));
|
||||
assertEquals('SafeName special chars.', '____', varDB.safeName_('!@#$'));
|
||||
assertEquals('SafeName reserved.', 'door', varDB.safeName_('door'));
|
||||
}
|
||||
|
||||
function test_getName() {
|
||||
var varDB = new Blockly.Names('window,door');
|
||||
assertEquals('Name add #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
|
||||
assertEquals('Name get #1.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
|
||||
assertEquals('Name add #2.', 'Foo_bar2', varDB.getName('Foo bar', 'var'));
|
||||
assertEquals('Name get #2.', 'Foo_bar2', varDB.getName('foo BAR', 'var'));
|
||||
assertEquals('Name add #3.', 'door2', varDB.getName('door', 'var'));
|
||||
assertEquals('Name add #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc'));
|
||||
assertEquals('Name get #1b.', 'Foo_bar', varDB.getName('Foo.bar', 'var'));
|
||||
assertEquals('Name get #4.', 'Foo_bar3', varDB.getName('Foo.bar', 'proc'));
|
||||
}
|
||||
|
||||
function test_getDistinctName() {
|
||||
var varDB = new Blockly.Names('window,door');
|
||||
assertEquals('Name distinct #1.', 'Foo_bar',
|
||||
varDB.getDistinctName('Foo.bar', 'var'));
|
||||
assertEquals('Name distinct #2.', 'Foo_bar2',
|
||||
varDB.getDistinctName('Foo.bar', 'var'));
|
||||
assertEquals('Name distinct #3.', 'Foo_bar3',
|
||||
varDB.getDistinctName('Foo.bar', 'proc'));
|
||||
varDB.reset();
|
||||
assertEquals('Name distinct #4.', 'Foo_bar',
|
||||
varDB.getDistinctName('Foo.bar', 'var'));
|
||||
}
|
||||
|
||||
function test_nameEquals() {
|
||||
assertTrue('Name equals #1.', Blockly.Names.equals('Foo.bar', 'Foo.bar'));
|
||||
assertFalse('Name equals #2.', Blockly.Names.equals('Foo.bar', 'Foo_bar'));
|
||||
assertTrue('Name equals #3.', Blockly.Names.equals('Foo.bar', 'FOO.BAR'));
|
||||
}
|
||||
84
node_modules/node-blockly/blockly/tests/jsunit/procedures_test.js
generated
vendored
Normal file
84
node_modules/node-blockly/blockly/tests/jsunit/procedures_test.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for procedures.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
|
||||
var workspace;
|
||||
|
||||
function proceduresTest_setUpWithMockBlocks() {
|
||||
workspace = new Blockly.Workspace();
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
getProcedureDef: function() {
|
||||
},
|
||||
'type': 'procedure_mock_block',
|
||||
'message0': '%1',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'field_variable',
|
||||
'name': 'NAME',
|
||||
'variable': 'item'
|
||||
}
|
||||
]
|
||||
}]);
|
||||
Blockly.Blocks['procedure_mock_block'].getProcedureDef = function() {
|
||||
return [this.getField('NAME').getText(), [], false];
|
||||
};
|
||||
}
|
||||
|
||||
function proceduresTest_tearDownWithMockBlocks() {
|
||||
workspace.dispose();
|
||||
delete Blockly.Blocks.procedures_mock_block;
|
||||
}
|
||||
|
||||
|
||||
function test_isNameUsed_NoBlocks() {
|
||||
workspace = new Blockly.Workspace();
|
||||
var result = Blockly.Procedures.isNameUsed('name1', workspace);
|
||||
assertFalse(result);
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_isNameUsed_False() {
|
||||
proceduresTest_setUpWithMockBlocks();
|
||||
workspace.createVariable('name2', '', 'id2');
|
||||
var block = new Blockly.Block(workspace, 'procedure_mock_block');
|
||||
block.setFieldValue('id2', 'NAME');
|
||||
|
||||
var result = Blockly.Procedures.isNameUsed('name1', workspace);
|
||||
assertFalse(result);
|
||||
proceduresTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_isNameUsed_True() {
|
||||
proceduresTest_setUpWithMockBlocks();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
var block = new Blockly.Block(workspace, 'procedure_mock_block');
|
||||
block.setFieldValue('id1', 'NAME');
|
||||
|
||||
var result = Blockly.Procedures.isNameUsed('name1', workspace);
|
||||
assertTrue(result);
|
||||
proceduresTest_tearDownWithMockBlocks();
|
||||
}
|
||||
35
node_modules/node-blockly/blockly/tests/jsunit/test_runner.js
generated
vendored
Normal file
35
node_modules/node-blockly/blockly/tests/jsunit/test_runner.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
var webdriverio = require('webdriverio');
|
||||
var options = {
|
||||
desiredCapabilities: {
|
||||
browserName: 'chrome'
|
||||
}
|
||||
};
|
||||
|
||||
var path = process.cwd();
|
||||
//TODO: change pause to waitunitl
|
||||
var browser = webdriverio
|
||||
.remote(options)
|
||||
.init()
|
||||
.url("file://" + path + "/tests/jsunit/index.html").pause(5000);
|
||||
|
||||
|
||||
browser
|
||||
.getHTML('#closureTestRunnerLog')
|
||||
.then(function(result) {
|
||||
// call js to parse html
|
||||
var regex = /[\d]+\spassed,\s([\d]+)\sfailed./i;
|
||||
var numOfFailure = regex.exec(result)[1];
|
||||
var regex2 = /Unit Tests for Blockly .*]/;
|
||||
var testStatus = regex2.exec(result)[0];
|
||||
console.log("============Blockly Unit Test Summary=================");
|
||||
console.log(testStatus);
|
||||
var regex3 = /\d+ passed,\s\d+ failed/;
|
||||
var detail = regex3.exec(result)[0];
|
||||
console.log(detail);
|
||||
console.log("============Blockly Unit Test Summary=================");
|
||||
if ( parseInt(numOfFailure) !== 0) {
|
||||
console.log(result);
|
||||
process.exit(1);
|
||||
}
|
||||
})
|
||||
.catch(function(err) { console.log(err); process.exit(1); });
|
||||
163
node_modules/node-blockly/blockly/tests/jsunit/test_utilities.js
generated
vendored
Normal file
163
node_modules/node-blockly/blockly/tests/jsunit/test_utilities.js
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Test utilities.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
|
||||
|
||||
/**
|
||||
* Check that two arrays have the same content.
|
||||
* @param {!Array.<string>} array1 The first array.
|
||||
* @param {!Array.<string>} array2 The second array.
|
||||
*/
|
||||
function isEqualArrays(array1, array2) {
|
||||
assertEquals(array1.length, array2.length);
|
||||
for (var i = 0; i < array1.length; i++) {
|
||||
assertEquals(array1[i], array2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a controlled MethodMock. Sets the expected return values and
|
||||
* the parameters if any exist. Sets the method to replay.
|
||||
* @param {!goog.testing.MockControl} mockControl Object that holds a set
|
||||
* of mocks for this test.
|
||||
* @param {!Object} scope The scope of the method to be mocked out.
|
||||
* @param {!string} funcName The name of the function we're going to mock.
|
||||
* @param {Array<Object>} parameters The parameters to call the mock with.
|
||||
* @param {Array<!Object>} return_values The values to return when called.
|
||||
* @return {!goog.testing.MockInterface} The mocked method.
|
||||
*/
|
||||
function setUpMockMethod(mockControl, scope, funcName, parameters,
|
||||
return_values) {
|
||||
var mockMethod = mockControl.createMethodMock(scope, funcName);
|
||||
if (return_values) {
|
||||
for (var i = 0, return_value; return_value = return_values[i]; i++) {
|
||||
if (parameters && i < parameters.length) {
|
||||
mockMethod(parameters[i]).$returns(return_value);
|
||||
}
|
||||
else {
|
||||
mockMethod().$returns(return_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If there are no return values but there are parameters, we are only
|
||||
// recording specific method calls.
|
||||
else if (parameters) {
|
||||
for (var i = 0; i < parameters.length; i++) {
|
||||
mockMethod(parameters[i]);
|
||||
}
|
||||
}
|
||||
mockMethod.$replay();
|
||||
return mockMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a variable with the given values exists.
|
||||
* @param {Blockly.Workspace|Blockly.VariableMap} container The workspace or
|
||||
* variableMap the checked variable belongs to.
|
||||
* @param {!string} name The expected name of the variable.
|
||||
* @param {!string} type The expected type of the variable.
|
||||
* @param {!string} id The expected id of the variable.
|
||||
*/
|
||||
function checkVariableValues(container, name, type, id) {
|
||||
var variable = container.getVariableById(id);
|
||||
assertNotUndefined(variable);
|
||||
assertEquals(name, variable.name);
|
||||
assertEquals(type, variable.type);
|
||||
assertEquals(id, variable.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a test get_var_block.
|
||||
* Will fail if get_var_block isn't defined.
|
||||
* @param {!Blockly.Workspace} workspace The workspace on which to create the
|
||||
* block.
|
||||
* @param {!string} variable_id The id of the variable to reference.
|
||||
* @return {!Blockly.Block} The created block.
|
||||
*/
|
||||
function createMockVarBlock(workspace, variable_id) {
|
||||
if (!Blockly.Blocks['get_var_block']) {
|
||||
fail();
|
||||
}
|
||||
// Turn off events to avoid testing XML at the same time.
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'get_var_block');
|
||||
block.inputList[0].fieldRow[0].setValue(variable_id);
|
||||
Blockly.Events.enable();
|
||||
return block;
|
||||
}
|
||||
|
||||
function createTwoVariablesAndBlocks(workspace) {
|
||||
// Create two variables of different types.
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.createVariable('name2', 'type2', 'id2');
|
||||
// Create blocks to refer to both of them.
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
createMockVarBlock(workspace, 'id2');
|
||||
}
|
||||
|
||||
function createVariableAndBlock(workspace) {
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
}
|
||||
|
||||
function defineGetVarBlock() {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "get_var_block",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_variable",
|
||||
"name": "VAR",
|
||||
"variableTypes": ["", "type1", "type2"]
|
||||
}
|
||||
]
|
||||
}]);
|
||||
}
|
||||
|
||||
function undefineGetVarBlock() {
|
||||
delete Blockly.Blocks['get_var_block'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture the strings sent to console.warn() when calling a function.
|
||||
* @param {function} innerFunc The function where warnings may called.
|
||||
* @return {string[]} The warning messages (only the first arguments).
|
||||
*/
|
||||
function captureWarnings(innerFunc) {
|
||||
var msgs = [];
|
||||
var nativeConsoleWarn = console.warn;
|
||||
try {
|
||||
console.warn = function(msg) {
|
||||
msgs.push(msg);
|
||||
nativeConsoleWarn.apply(console, arguments);
|
||||
};
|
||||
innerFunc();
|
||||
} finally {
|
||||
console.warn = nativeConsoleWarn;
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
234
node_modules/node-blockly/blockly/tests/jsunit/utils_test.js
generated
vendored
Normal file
234
node_modules/node-blockly/blockly/tests/jsunit/utils_test.js
generated
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2011 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function test_genUid() {
|
||||
var uuids = {};
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
var uuid = Blockly.utils.genUid();
|
||||
assertFalse('UUID different: ' + uuid, uuid in uuids);
|
||||
uuids[uuid] = true;
|
||||
}
|
||||
}
|
||||
|
||||
function test_addClass() {
|
||||
var p = document.createElement('p');
|
||||
Blockly.utils.addClass(p, 'one');
|
||||
assertEquals('Adding "one"', 'one', p.className);
|
||||
Blockly.utils.addClass(p, 'one');
|
||||
assertEquals('Adding duplicate "one"', 'one', p.className);
|
||||
Blockly.utils.addClass(p, 'two');
|
||||
assertEquals('Adding "two"', 'one two', p.className);
|
||||
Blockly.utils.addClass(p, 'two');
|
||||
assertEquals('Adding duplicate "two"', 'one two', p.className);
|
||||
Blockly.utils.addClass(p, 'three');
|
||||
assertEquals('Adding "three"', 'one two three', p.className);
|
||||
}
|
||||
|
||||
function test_hasClass() {
|
||||
var p = document.createElement('p');
|
||||
p.className = ' one three two three ';
|
||||
assertTrue('Has "one"', Blockly.utils.hasClass(p, 'one'));
|
||||
assertTrue('Has "two"', Blockly.utils.hasClass(p, 'two'));
|
||||
assertTrue('Has "three"', Blockly.utils.hasClass(p, 'three'));
|
||||
assertFalse('Has no "four"', Blockly.utils.hasClass(p, 'four'));
|
||||
assertFalse('Has no "t"', Blockly.utils.hasClass(p, 't'));
|
||||
}
|
||||
|
||||
function test_removeClass() {
|
||||
var p = document.createElement('p');
|
||||
p.className = ' one three two three ';
|
||||
Blockly.utils.removeClass(p, 'two');
|
||||
assertEquals('Removing "two"', 'one three three', p.className);
|
||||
Blockly.utils.removeClass(p, 'four');
|
||||
assertEquals('Removing "four"', 'one three three', p.className);
|
||||
Blockly.utils.removeClass(p, 'three');
|
||||
assertEquals('Removing "three"', 'one', p.className);
|
||||
Blockly.utils.removeClass(p, 'ne');
|
||||
assertEquals('Removing "ne"', 'one', p.className);
|
||||
Blockly.utils.removeClass(p, 'one');
|
||||
assertEquals('Removing "one"', '', p.className);
|
||||
Blockly.utils.removeClass(p, 'zero');
|
||||
assertEquals('Removing "zero"', '', p.className);
|
||||
}
|
||||
|
||||
function test_shortestStringLength() {
|
||||
var len = Blockly.utils.shortestStringLength('one,two,three,four,five'.split(','));
|
||||
assertEquals('Length of "one"', 3, len);
|
||||
len = Blockly.utils.shortestStringLength('one,two,three,four,five,'.split(','));
|
||||
assertEquals('Length of ""', 0, len);
|
||||
len = Blockly.utils.shortestStringLength(['Hello World']);
|
||||
assertEquals('List of one', 11, len);
|
||||
len = Blockly.utils.shortestStringLength([]);
|
||||
assertEquals('Empty list', 0, len);
|
||||
}
|
||||
|
||||
function test_commonWordPrefix() {
|
||||
var len = Blockly.utils.commonWordPrefix('one,two,three,four,five'.split(','));
|
||||
assertEquals('No prefix', 0, len);
|
||||
len = Blockly.utils.commonWordPrefix('Xone,Xtwo,Xthree,Xfour,Xfive'.split(','));
|
||||
assertEquals('No word prefix', 0, len);
|
||||
len = Blockly.utils.commonWordPrefix('abc de,abc de,abc de,abc de'.split(','));
|
||||
assertEquals('Full equality', 6, len);
|
||||
len = Blockly.utils.commonWordPrefix('abc deX,abc deY'.split(','));
|
||||
assertEquals('One word prefix', 4, len);
|
||||
len = Blockly.utils.commonWordPrefix('abc de,abc deY'.split(','));
|
||||
assertEquals('Overflow no', 4, len);
|
||||
len = Blockly.utils.commonWordPrefix('abc de,abc de Y'.split(','));
|
||||
assertEquals('Overflow yes', 6, len);
|
||||
len = Blockly.utils.commonWordPrefix(['Hello World']);
|
||||
assertEquals('List of one', 11, len);
|
||||
len = Blockly.utils.commonWordPrefix([]);
|
||||
assertEquals('Empty list', 0, len);
|
||||
len = Blockly.utils.commonWordPrefix('turn left,turn right'.split(','));
|
||||
assertEquals('No prefix due to &nbsp;', 0, len);
|
||||
len = Blockly.utils.commonWordPrefix('turn\u00A0left,turn\u00A0right'.split(','));
|
||||
assertEquals('No prefix due to \\u00A0', 0, len);
|
||||
}
|
||||
|
||||
function test_commonWordSuffix() {
|
||||
var len = Blockly.utils.commonWordSuffix('one,two,three,four,five'.split(','));
|
||||
assertEquals('No prefix', 0, len);
|
||||
len = Blockly.utils.commonWordSuffix('oneX,twoX,threeX,fourX,fiveX'.split(','));
|
||||
assertEquals('No word prefix', 0, len);
|
||||
len = Blockly.utils.commonWordSuffix('abc de,abc de,abc de,abc de'.split(','));
|
||||
assertEquals('Full equality', 6, len);
|
||||
len = Blockly.utils.commonWordSuffix('Xabc de,Yabc de'.split(','));
|
||||
assertEquals('One word prefix', 3, len);
|
||||
len = Blockly.utils.commonWordSuffix('abc de,Yabc de'.split(','));
|
||||
assertEquals('Overflow no', 3, len);
|
||||
len = Blockly.utils.commonWordSuffix('abc de,Y abc de'.split(','));
|
||||
assertEquals('Overflow yes', 6, len);
|
||||
len = Blockly.utils.commonWordSuffix(['Hello World']);
|
||||
assertEquals('List of one', 11, len);
|
||||
len = Blockly.utils.commonWordSuffix([]);
|
||||
assertEquals('Empty list', 0, len);
|
||||
}
|
||||
|
||||
function test_tokenizeInterpolation() {
|
||||
var tokens = Blockly.utils.tokenizeInterpolation('');
|
||||
assertArrayEquals('Null interpolation', [], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('Hello');
|
||||
assertArrayEquals('No interpolation', ['Hello'], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('Hello%World');
|
||||
assertArrayEquals('Unescaped %.', ['Hello%World'], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('Hello%%World');
|
||||
assertArrayEquals('Escaped %.', ['Hello%World'], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('Hello %1 World');
|
||||
assertArrayEquals('Interpolation.', ['Hello ', 1, ' World'], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%123Hello%456World%789');
|
||||
assertArrayEquals('Interpolations.', [123, 'Hello', 456, 'World', 789], tokens);
|
||||
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%%%x%%0%00%01%');
|
||||
assertArrayEquals('Torture interpolations.', ['%%x%0', 0, 1, '%'], tokens);
|
||||
|
||||
Blockly.Msg = Blockly.Msg || {};
|
||||
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%{bky_string_ref}');
|
||||
assertArrayEquals('String table reference, lowercase', ['test string'], tokens);
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%{BKY_STRING_REF}');
|
||||
assertArrayEquals('String table reference, uppercase', ['test string'], tokens);
|
||||
|
||||
Blockly.Msg.WITH_PARAM = 'before %1 after';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%{bky_with_param}');
|
||||
assertArrayEquals('String table reference, with parameter', ['before ', 1, ' after'], tokens);
|
||||
|
||||
Blockly.Msg.RECURSE = 'before %{bky_string_ref} after';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%{bky_recurse}');
|
||||
assertArrayEquals('String table reference, with subreference', ['before test string after'], tokens);
|
||||
|
||||
// Error cases...
|
||||
tokens = Blockly.utils.tokenizeInterpolation('%{bky_undefined}');
|
||||
assertArrayEquals('Undefined string table reference', ['%{bky_undefined}'], tokens);
|
||||
|
||||
Blockly.Msg['1'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{1} after');
|
||||
assertArrayEquals('Invalid initial digit in string table reference', ['before %{1} after'], tokens);
|
||||
|
||||
Blockly.Msg['TWO WORDS'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{two words} after');
|
||||
assertArrayEquals('Invalid character in string table reference: space', ['before %{two words} after'], tokens);
|
||||
|
||||
Blockly.Msg['TWO-WORDS'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{two-words} after');
|
||||
assertArrayEquals('Invalid character in string table reference: dash', ['before %{two-words} after'], tokens);
|
||||
|
||||
Blockly.Msg['TWO.WORDS'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{two.words} after');
|
||||
assertArrayEquals('Invalid character in string table reference: period', ['before %{two.words} after'], tokens);
|
||||
|
||||
Blockly.Msg['AB&C'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{ab&c} after');
|
||||
assertArrayEquals('Invalid character in string table reference: &', ['before %{ab&c} after'], tokens);
|
||||
|
||||
Blockly.Msg['UNCLOSED'] = 'Will not match';
|
||||
tokens = Blockly.utils.tokenizeInterpolation('before %{unclosed');
|
||||
assertArrayEquals('String table reference, with parameter', ['before %{unclosed'], tokens);
|
||||
}
|
||||
|
||||
function test_replaceMessageReferences() {
|
||||
Blockly.Msg = Blockly.Msg || {};
|
||||
Blockly.Msg.STRING_REF = 'test string';
|
||||
Blockly.Msg.SUBREF = 'subref';
|
||||
Blockly.Msg.STRING_REF_WITH_ARG = 'test %1 string';
|
||||
Blockly.Msg.STRING_REF_WITH_SUBREF = 'test %{bky_subref} string';
|
||||
|
||||
var resultString = Blockly.utils.replaceMessageReferences('');
|
||||
assertEquals('Empty string produces empty string', '', resultString);
|
||||
|
||||
resultString = Blockly.utils.replaceMessageReferences('%%');
|
||||
assertEquals('Escaped %', '%', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('%%{bky_string_ref}');
|
||||
assertEquals('Escaped %', '%{bky_string_ref}', resultString);
|
||||
|
||||
resultString = Blockly.utils.replaceMessageReferences('%a');
|
||||
assertEquals('Unrecognized % escape code treated as literal', '%a', resultString);
|
||||
|
||||
resultString = Blockly.utils.replaceMessageReferences('%1');
|
||||
assertEquals('Interpolation tokens ignored.', '%1', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('%1 %2');
|
||||
assertEquals('Interpolation tokens ignored.', '%1 %2', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('before %1 after');
|
||||
assertEquals('Interpolation tokens ignored.', 'before %1 after', resultString);
|
||||
|
||||
// Blockly.Msg.STRING_REF cases:
|
||||
resultString = Blockly.utils.replaceMessageReferences('%{bky_string_ref}');
|
||||
assertEquals('Message ref dereferenced.', 'test string', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('before %{bky_string_ref} after');
|
||||
assertEquals('Message ref dereferenced.', 'before test string after', resultString);
|
||||
|
||||
// Blockly.Msg.STRING_REF_WITH_ARG cases:
|
||||
resultString = Blockly.utils.replaceMessageReferences('%{bky_string_ref_with_arg}');
|
||||
assertEquals('Message ref dereferenced with argument preserved.', 'test %1 string', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('before %{bky_string_ref_with_arg} after');
|
||||
assertEquals('Message ref dereferenced with argument preserved.', 'before test %1 string after', resultString);
|
||||
|
||||
// Blockly.Msg.STRING_REF_WITH_SUBREF cases:
|
||||
resultString = Blockly.utils.replaceMessageReferences('%{bky_string_ref_with_subref}');
|
||||
assertEquals('Message ref and subref dereferenced.', 'test subref string', resultString);
|
||||
resultString = Blockly.utils.replaceMessageReferences('before %{bky_string_ref_with_subref} after');
|
||||
assertEquals('Message ref and subref dereferenced.', 'before test subref string after', resultString);
|
||||
}
|
||||
300
node_modules/node-blockly/blockly/tests/jsunit/variable_map_test.js
generated
vendored
Normal file
300
node_modules/node-blockly/blockly/tests/jsunit/variable_map_test.js
generated
vendored
Normal file
@@ -0,0 +1,300 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for variable map.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
var variable_map;
|
||||
var mockControl_;
|
||||
var workspace;
|
||||
|
||||
function variableMapTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
variable_map = new Blockly.VariableMap(workspace);
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
}
|
||||
|
||||
function variableMapTest_tearDown() {
|
||||
workspace.dispose();
|
||||
mockControl_.$tearDown();
|
||||
variable_map = null;
|
||||
}
|
||||
|
||||
function test_getVariable_ByNameAndType() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', 'type1', 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', 'type1', 'id2');
|
||||
var var_3 = variable_map.createVariable('name3', 'type2', 'id3');
|
||||
var result_1 = variable_map.getVariable('name1', 'type1');
|
||||
var result_2 = variable_map.getVariable('name2', 'type1');
|
||||
var result_3 = variable_map.getVariable('name3', 'type2');
|
||||
|
||||
// Searching by name + type is correct.
|
||||
assertEquals(var_1, result_1);
|
||||
assertEquals(var_2, result_2);
|
||||
assertEquals(var_3, result_3);
|
||||
|
||||
// Searching only by name defaults to the '' type.
|
||||
assertNull(variable_map.getVariable('name1'));
|
||||
assertNull(variable_map.getVariable('name2'));
|
||||
assertNull(variable_map.getVariable('name3'));
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariable_NotFound() {
|
||||
variableMapTest_setUp();
|
||||
var result = variable_map.getVariable('name1');
|
||||
assertNull(result);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariableById_Trivial() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', 'type1', 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', 'type1', 'id2');
|
||||
var var_3 = variable_map.createVariable('name3', 'type2', 'id3');
|
||||
var result_1 = variable_map.getVariableById('id1');
|
||||
var result_2 = variable_map.getVariableById('id2');
|
||||
var result_3 = variable_map.getVariableById('id3');
|
||||
|
||||
assertEquals(var_1, result_1);
|
||||
assertEquals(var_2, result_2);
|
||||
assertEquals(var_3, result_3);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariableById_NotFound() {
|
||||
variableMapTest_setUp();
|
||||
var result = variable_map.getVariableById('id1');
|
||||
assertNull(result);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableTrivial() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableAlreadyExists() {
|
||||
// Expect that when the variable already exists, the variableMap_ is unchanged.
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
|
||||
// Assert there is only one variable in the variable_map.
|
||||
var keys = Object.keys(variable_map.variableMap_);
|
||||
assertEquals(1, keys.length);
|
||||
var varMapLength = variable_map.variableMap_[keys[0]].length;
|
||||
assertEquals(1, varMapLength);
|
||||
|
||||
variable_map.createVariable('name1', 'type1');
|
||||
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
|
||||
// Check that the size of the variableMap_ did not change.
|
||||
keys = Object.keys(variable_map.variableMap_);
|
||||
assertEquals(1, keys.length);
|
||||
varMapLength = variable_map.variableMap_[keys[0]].length;
|
||||
assertEquals(1, varMapLength);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableNameAlreadyExists() {
|
||||
// Expect that when a variable with the same name but a different type already
|
||||
// exists, the new variable is created.
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
|
||||
// Assert there is only one variable in the variable_map.
|
||||
var keys = Object.keys(variable_map.variableMap_);
|
||||
assertEquals(1, keys.length);
|
||||
var varMapLength = variable_map.variableMap_[keys[0]].length;
|
||||
assertEquals(1, varMapLength);
|
||||
|
||||
variable_map.createVariable('name1', 'type2', 'id2');
|
||||
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(variable_map, 'name1', 'type2', 'id2');
|
||||
// Check that the size of the variableMap_ did change.
|
||||
keys = Object.keys(variable_map.variableMap_);
|
||||
assertEquals(2, keys.length);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
function test_createVariableNullAndUndefinedType() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', null, 'id1');
|
||||
variable_map.createVariable('name2', undefined, 'id2');
|
||||
|
||||
checkVariableValues(variable_map, 'name1', '', 'id1');
|
||||
checkVariableValues(variable_map, 'name2', '', 'id2');
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableNullId() {
|
||||
variableMapTest_setUp();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
variable_map.createVariable('name1', 'type1', null);
|
||||
checkVariableValues(variable_map, 'name1', 'type1', '1');
|
||||
} finally {
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_createVariableUndefinedId() {
|
||||
variableMapTest_setUp();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']);
|
||||
try {
|
||||
variable_map.createVariable('name1', 'type1', undefined);
|
||||
checkVariableValues(variable_map, 'name1', 'type1', '1');
|
||||
} finally {
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_createVariableIdAlreadyExists() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
try {
|
||||
variable_map.createVariable('name2', 'type2', 'id1');
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableMismatchedIdAndType() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
try {
|
||||
variable_map.createVariable('name1', 'type2', 'id1');
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
variable_map.createVariable('name1', 'type1', 'id2');
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
}
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_createVariableTwoSameTypes() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
variable_map.createVariable('name2', 'type1', 'id2');
|
||||
|
||||
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(variable_map, 'name2', 'type1', 'id2');
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariablesOfType_Trivial() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', 'type1', 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', 'type1', 'id2');
|
||||
variable_map.createVariable('name3', 'type2', 'id3');
|
||||
variable_map.createVariable('name4', 'type3', 'id4');
|
||||
var result_array_1 = variable_map.getVariablesOfType('type1');
|
||||
var result_array_2 = variable_map.getVariablesOfType('type5');
|
||||
isEqualArrays([var_1, var_2], result_array_1);
|
||||
isEqualArrays([], result_array_2);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariablesOfType_Null() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', '', 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', '', 'id2');
|
||||
var var_3 = variable_map.createVariable('name3', '', 'id3');
|
||||
variable_map.createVariable('name4', 'type1', 'id4');
|
||||
var result_array = variable_map.getVariablesOfType(null);
|
||||
isEqualArrays([var_1, var_2, var_3], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariablesOfType_EmptyString() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', null, 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', null, 'id2');
|
||||
var result_array = variable_map.getVariablesOfType('');
|
||||
isEqualArrays([var_1, var_2], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariablesOfType_Deleted() {
|
||||
variableMapTest_setUp();
|
||||
var variable = variable_map.createVariable('name1', null, 'id1');
|
||||
variable_map.deleteVariable(variable);
|
||||
var result_array = variable_map.getVariablesOfType('');
|
||||
isEqualArrays([], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariablesOfType_DoesNotExist() {
|
||||
variableMapTest_setUp();
|
||||
var result_array = variable_map.getVariablesOfType('type1');
|
||||
isEqualArrays([], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariableTypes_Trivial() {
|
||||
variableMapTest_setUp();
|
||||
variable_map.createVariable('name1', 'type1', 'id1');
|
||||
variable_map.createVariable('name2', 'type1', 'id2');
|
||||
variable_map.createVariable('name3', 'type2', 'id3');
|
||||
variable_map.createVariable('name4', 'type3', 'id4');
|
||||
var result_array = variable_map.getVariableTypes();
|
||||
// The empty string is always an option.
|
||||
isEqualArrays(['type1', 'type2', 'type3', ''], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getVariableTypes_None() {
|
||||
variableMapTest_setUp();
|
||||
// The empty string is always an option.
|
||||
var result_array = variable_map.getVariableTypes();
|
||||
isEqualArrays([''], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getAllVariables_Trivial() {
|
||||
variableMapTest_setUp();
|
||||
var var_1 = variable_map.createVariable('name1', 'type1', 'id1');
|
||||
var var_2 = variable_map.createVariable('name2', 'type1', 'id2');
|
||||
var var_3 = variable_map.createVariable('name3', 'type2', 'id3');
|
||||
var result_array = variable_map.getAllVariables();
|
||||
isEqualArrays([var_1, var_2, var_3], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
|
||||
function test_getAllVariables_None() {
|
||||
variableMapTest_setUp();
|
||||
var result_array = variable_map.getAllVariables();
|
||||
isEqualArrays([], result_array);
|
||||
variableMapTest_tearDown();
|
||||
}
|
||||
91
node_modules/node-blockly/blockly/tests/jsunit/variable_model_test.js
generated
vendored
Normal file
91
node_modules/node-blockly/blockly/tests/jsunit/variable_model_test.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for variable model.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var variable;
|
||||
var workspace;
|
||||
|
||||
function variableModelTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
}
|
||||
|
||||
function variableModelTest_tearDown() {
|
||||
workspace.dispose();
|
||||
variable = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* These tests check the constructor of the variable model.
|
||||
*/
|
||||
function testInit_Trivial() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type',
|
||||
'test_id');
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertEquals('test_id', variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_NullType() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', null, 'test_id');
|
||||
assertEquals('', variable.type);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_UndefinedType() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', undefined, 'test_id');
|
||||
assertEquals('', variable.type);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_NullId() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type', null);
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_UndefinedId() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test', 'test_type', undefined);
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('test_type', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
|
||||
function testInit_OnlyNameProvided() {
|
||||
variableModelTest_setUp();
|
||||
variable = new Blockly.VariableModel(workspace, 'test');
|
||||
assertEquals('test', variable.name);
|
||||
assertEquals('', variable.type);
|
||||
assertNotNull(variable.id_);
|
||||
variableModelTest_tearDown();
|
||||
}
|
||||
99
node_modules/node-blockly/blockly/tests/jsunit/variables_test.js
generated
vendored
Normal file
99
node_modules/node-blockly/blockly/tests/jsunit/variables_test.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2018 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for variable utility functions in Blockly
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
|
||||
function variablesTest_setUp() {
|
||||
defineGetVarBlock();
|
||||
var workspace = new Blockly.Workspace();
|
||||
workspace.createVariable('foo', 'type1', '1');
|
||||
workspace.createVariable('bar', 'type1', '2');
|
||||
workspace.createVariable('baz', 'type1', '3');
|
||||
return workspace;
|
||||
}
|
||||
|
||||
function variablesTest_tearDown(workspace) {
|
||||
undefineGetVarBlock();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function buildVariablesTest(testImpl) {
|
||||
return function() {
|
||||
var workspace = variablesTest_setUp();
|
||||
try {
|
||||
testImpl(workspace);
|
||||
} finally {
|
||||
variablesTest_tearDown(workspace);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var test_allUsedVarModels = buildVariablesTest(
|
||||
function(workspace) {
|
||||
createMockVarBlock(workspace, '1');
|
||||
createMockVarBlock(workspace, '2');
|
||||
createMockVarBlock(workspace, '3');
|
||||
|
||||
var result = Blockly.Variables.allUsedVarModels(workspace);
|
||||
assertEquals('Expected three variables in the list of used variables',
|
||||
3, result.length);
|
||||
}
|
||||
);
|
||||
|
||||
var test_allUsedVarModels_someUnused = buildVariablesTest(
|
||||
function(workspace) {
|
||||
createMockVarBlock(workspace, '2');
|
||||
|
||||
var result = Blockly.Variables.allUsedVarModels(workspace);
|
||||
assertEquals('Expected one variable in the list of used variables',
|
||||
1, result.length);
|
||||
assertEquals('Expected variable with ID 2 in the list of used variables',
|
||||
'2', result[0].getId());
|
||||
}
|
||||
);
|
||||
|
||||
var test_allUsedVarModels_varUsedTwice = buildVariablesTest(
|
||||
function(workspace) {
|
||||
createMockVarBlock(workspace, '2');
|
||||
createMockVarBlock(workspace, '2');
|
||||
|
||||
var result = Blockly.Variables.allUsedVarModels(workspace);
|
||||
// Using the same variable multiple times should not change the number of
|
||||
// elements in the list.
|
||||
assertEquals('Expected one variable in the list of used variables',
|
||||
1, result.length);
|
||||
assertEquals('Expected variable with ID 2 in the list of used variables',
|
||||
'2', result[0].getId());
|
||||
}
|
||||
);
|
||||
|
||||
var test_allUsedVarModels_allUnused = buildVariablesTest(
|
||||
function(workspace) {
|
||||
var result = Blockly.Variables.allUsedVarModels(workspace);
|
||||
assertEquals('Expected no variables in the list of used variables',
|
||||
0, result.length);
|
||||
}
|
||||
);
|
||||
153
node_modules/node-blockly/blockly/tests/jsunit/widget_div_test.js
generated
vendored
Normal file
153
node_modules/node-blockly/blockly/tests/jsunit/widget_div_test.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
|
||||
function widgetdiv_testHelper_makeBBox(left, top, width, height) {
|
||||
return {
|
||||
left: left,
|
||||
right: left + width,
|
||||
top: top,
|
||||
bottom: top + height
|
||||
};
|
||||
}
|
||||
|
||||
function widgetdiv_testHelper_makeSize(width, height) {
|
||||
return {
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
}
|
||||
|
||||
var widgetDiv_test_viewport = widgetdiv_testHelper_makeBBox(0, 0, 1000, 1000);
|
||||
var widgetDiv_test_widgetSize = widgetdiv_testHelper_makeSize(100, 100);
|
||||
|
||||
// Anchor is always 90 px wide and 90 px tall for this test.
|
||||
var widgetDiv_test_anchorSize = 90;
|
||||
|
||||
function widgetdiv_testHelper_makeAnchor(left, top) {
|
||||
return {
|
||||
left: left,
|
||||
right: left + widgetDiv_test_anchorSize,
|
||||
top: top,
|
||||
bottom: top + widgetDiv_test_anchorSize
|
||||
};
|
||||
}
|
||||
|
||||
function test_widgetDiv_topConflict() {
|
||||
var anchorTop = 50;
|
||||
// Anchor placed close to the top.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(500, anchorTop);
|
||||
|
||||
// The widget div should be placed just below the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateY_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize);
|
||||
assertEquals(anchorTop + widgetDiv_test_anchorSize, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_bottomConflict() {
|
||||
var anchorTop = 900;
|
||||
// Anchor placed close to the bottom.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(500, anchorTop);
|
||||
|
||||
// The widget div should be placed just above the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateY_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize);
|
||||
assertEquals(anchorTop - widgetDiv_test_widgetSize.height, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_noYConflict() {
|
||||
var anchorTop = 500;
|
||||
// Anchor placed in the middle.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(500, anchorTop);
|
||||
|
||||
// The widget div should be placed just below the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateY_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize);
|
||||
assertEquals(anchorTop + widgetDiv_test_anchorSize, calculated);
|
||||
}
|
||||
|
||||
|
||||
function test_widgetDiv_leftConflict_LTR() {
|
||||
var anchorLeft = 50;
|
||||
// Anchor placed close to the left side.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
|
||||
// The widget div should be placed at the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, false /* rtl */);
|
||||
assertEquals(anchorLeft, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_rightConflict_LTR() {
|
||||
var anchorLeft = 950;
|
||||
// Anchor placed close to the right side.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
|
||||
// The widget div should be placed as far right as possible--at the edge of
|
||||
// the screen.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, false /* rtl */);
|
||||
assertEquals(1000 - widgetDiv_test_widgetSize.width, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_noXConflict_LTR() {
|
||||
var anchorLeft = 500;
|
||||
// Anchor in the middle
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
// The widget div should be placed just at the left side of the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, false /* rtl */);
|
||||
assertEquals(anchorLeft, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_leftConflict_RTL() {
|
||||
var anchorLeft = 10;
|
||||
// Anchor placed close to the left side.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
// The widget div should be placed as far left as possible--at the edge of
|
||||
// the screen.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, true /* rtl */);
|
||||
assertEquals(0, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_rightConflict_RTL() {
|
||||
var anchorLeft = 950;
|
||||
// Anchor placed close to the right side.
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
|
||||
// The widget div should be placed as far right as possible--at the edge of
|
||||
// the screen.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, true /* rtl */);
|
||||
assertEquals(1000 - widgetDiv_test_widgetSize.width, calculated);
|
||||
}
|
||||
|
||||
function test_widgetDiv_noXConflict_RTL() {
|
||||
var anchorLeft = 500;
|
||||
// anchor placed in the middle
|
||||
var anchorBBox = widgetdiv_testHelper_makeAnchor(anchorLeft, 500);
|
||||
// The widget div should be placed at the right side of the anchor.
|
||||
var calculated = Blockly.WidgetDiv.calculateX_(widgetDiv_test_viewport,
|
||||
anchorBBox, widgetDiv_test_widgetSize, true /* rtl */);
|
||||
assertEquals(anchorBBox.right - widgetDiv_test_widgetSize.width, calculated);
|
||||
}
|
||||
376
node_modules/node-blockly/blockly/tests/jsunit/workspace_test.js
generated
vendored
Normal file
376
node_modules/node-blockly/blockly/tests/jsunit/workspace_test.js
generated
vendored
Normal file
@@ -0,0 +1,376 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2012 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
var workspace;
|
||||
var mockControl_;
|
||||
|
||||
function workspaceTest_setUp() {
|
||||
defineGetVarBlock();
|
||||
workspace = new Blockly.Workspace();
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
}
|
||||
|
||||
function workspaceTest_tearDown() {
|
||||
undefineGetVarBlock();
|
||||
mockControl_.$tearDown();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_emptyWorkspace() {
|
||||
workspaceTest_setUp();
|
||||
try {
|
||||
assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_flatWorkspace() {
|
||||
workspaceTest_setUp();
|
||||
try {
|
||||
var blockA = workspace.newBlock('');
|
||||
assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length);
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length);
|
||||
blockA.dispose();
|
||||
assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_maxBlocksWorkspace() {
|
||||
workspaceTest_setUp();
|
||||
try {
|
||||
var blockA = workspace.newBlock('');
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Infinite capacity.', Infinity, workspace.remainingCapacity());
|
||||
workspace.options.maxBlocks = 3;
|
||||
assertEquals('Three capacity.', 1, workspace.remainingCapacity());
|
||||
workspace.options.maxBlocks = 2;
|
||||
assertEquals('Two capacity.', 0, workspace.remainingCapacity());
|
||||
workspace.options.maxBlocks = 1;
|
||||
assertEquals('One capacity.', -1, workspace.remainingCapacity());
|
||||
workspace.options.maxBlocks = 0;
|
||||
assertEquals('Zero capacity.', -2, workspace.remainingCapacity());
|
||||
workspace.clear();
|
||||
assertEquals('Cleared capacity.', 0, workspace.remainingCapacity());
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_getWorkspaceById() {
|
||||
var workspaceA = new Blockly.Workspace();
|
||||
var workspaceB = new Blockly.Workspace();
|
||||
try {
|
||||
assertEquals('Find workspaceA.', workspaceA,
|
||||
Blockly.Workspace.getById(workspaceA.id));
|
||||
assertEquals('Find workspaceB.', workspaceB,
|
||||
Blockly.Workspace.getById(workspaceB.id));
|
||||
assertEquals('No workspace found.', null,
|
||||
Blockly.Workspace.getById('I do not exist.'));
|
||||
workspaceA.dispose();
|
||||
assertEquals('Can\'t find workspaceA.', null,
|
||||
Blockly.Workspace.getById(workspaceA.id));
|
||||
assertEquals('WorkspaceB exists.', workspaceB,
|
||||
Blockly.Workspace.getById(workspaceB.id));
|
||||
} finally {
|
||||
workspaceB.dispose();
|
||||
workspaceA.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_getBlockById() {
|
||||
workspaceTest_setUp();
|
||||
try {
|
||||
var blockA = workspace.newBlock('');
|
||||
var blockB = workspace.newBlock('');
|
||||
assertEquals('Find blockA.', blockA, workspace.getBlockById(blockA.id));
|
||||
assertEquals('Find blockB.', blockB, workspace.getBlockById(blockB.id));
|
||||
assertEquals('No block found.', null,
|
||||
workspace.getBlockById('I do not exist.'));
|
||||
blockA.dispose();
|
||||
assertEquals('Can\'t find blockA.', null, workspace.getBlockById(blockA.id));
|
||||
assertEquals('BlockB exists.', blockB, workspace.getBlockById(blockB.id));
|
||||
workspace.clear();
|
||||
assertEquals('Can\'t find blockB.', null, workspace.getBlockById(blockB.id));
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_deleteVariable_InternalTrivial() {
|
||||
workspaceTest_setUp();
|
||||
var var_1 = workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.createVariable('name2', 'type2', 'id2');
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
createMockVarBlock(workspace, 'id2');
|
||||
|
||||
var uses = workspace.getVariableUsesById(var_1.getId());
|
||||
workspace.deleteVariableInternal_(var_1, uses);
|
||||
|
||||
var variable = workspace.getVariableById('id1');
|
||||
var block_var_name = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
assertNull(variable);
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
assertEquals('name2', block_var_name);
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
// TODO(marisaleung): Test the alert for deleting a variable that is a procedure.
|
||||
|
||||
function test_addTopBlock_TrivialFlyoutIsTrue() {
|
||||
workspaceTest_setUp();
|
||||
var targetWorkspace = new Blockly.Workspace();
|
||||
workspace.isFlyout = true;
|
||||
workspace.targetWorkspace = targetWorkspace;
|
||||
targetWorkspace.createVariable('name1', '', '1');
|
||||
|
||||
// Flyout.init usually does this binding.
|
||||
workspace.variableMap_ = targetWorkspace.getVariableMap();
|
||||
|
||||
try {
|
||||
var block = createMockVarBlock(workspace, '1');
|
||||
workspace.removeTopBlock(block);
|
||||
workspace.addTopBlock(block);
|
||||
checkVariableValues(workspace, 'name1', '', '1');
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
// Have to dispose of the main workspace after the flyout workspace, because
|
||||
// it holds the variable map.
|
||||
// Normally the main workspace disposes of the flyout workspace.
|
||||
targetWorkspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_clear_Trivial() {
|
||||
workspaceTest_setUp();
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.createVariable('name2', 'type2', 'id2');
|
||||
setUpMockMethod(mockControl_, Blockly.Events, 'setGroup', [true, false],
|
||||
null);
|
||||
|
||||
try {
|
||||
workspace.clear();
|
||||
var topBlocks_length = workspace.topBlocks_.length;
|
||||
var varMapLength = Object.keys(workspace.variableMap_.variableMap_).length;
|
||||
assertEquals(0, topBlocks_length);
|
||||
assertEquals(0, varMapLength);
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_clear_NoVariables() {
|
||||
workspaceTest_setUp();
|
||||
setUpMockMethod(mockControl_, Blockly.Events, 'setGroup', [true, false],
|
||||
null);
|
||||
|
||||
try {
|
||||
workspace.clear();
|
||||
var topBlocks_length = workspace.topBlocks_.length;
|
||||
var varMapLength = Object.keys(workspace.variableMap_.variableMap_).length;
|
||||
assertEquals(0, topBlocks_length);
|
||||
assertEquals(0, varMapLength);
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_renameVariable_NoReference() {
|
||||
// Test renaming a variable in the simplest case: when no blocks refer to it.
|
||||
workspaceTest_setUp();
|
||||
var id = 'id1';
|
||||
var type = 'type1';
|
||||
var oldName = 'name1';
|
||||
var newName = 'name2';
|
||||
workspace.createVariable(oldName, type, id);
|
||||
|
||||
try {
|
||||
workspace.renameVariableById(id, newName);
|
||||
checkVariableValues(workspace, newName, type, id);
|
||||
// Renaming should not have created a new variable.
|
||||
assertEquals(1, workspace.getAllVariables().length);
|
||||
} finally {
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
function test_renameVariable_ReferenceExists() {
|
||||
// Test renaming a variable when a reference to it exists.
|
||||
// Expect 'renameVariable' to change oldName variable name to newName.
|
||||
workspaceTest_setUp();
|
||||
var newName = 'name2';
|
||||
|
||||
createVariableAndBlock(workspace);
|
||||
|
||||
workspace.renameVariableById('id1', newName);
|
||||
checkVariableValues(workspace, newName, 'type1', 'id1');
|
||||
// Renaming should not have created a new variable.
|
||||
assertEquals(1, workspace.getAllVariables().length);
|
||||
var block_var_name = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
assertEquals(newName, block_var_name);
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
function test_renameVariable_TwoVariablesSameType() {
|
||||
// Expect 'renameVariable' to change oldName variable name to newName.
|
||||
// Expect oldName block name to change to newName
|
||||
workspaceTest_setUp();
|
||||
var id1 = 'id1';
|
||||
var id2 = 'id2';
|
||||
var type = 'type1';
|
||||
|
||||
var oldName = 'name1';
|
||||
var newName = 'name2';
|
||||
// Create two variables of the same type.
|
||||
workspace.createVariable(oldName, type, id1);
|
||||
workspace.createVariable(newName, type, id2);
|
||||
// Create blocks to refer to both of them.
|
||||
createMockVarBlock(workspace, id1);
|
||||
createMockVarBlock(workspace, id2);
|
||||
|
||||
workspace.renameVariableById(id1, newName);
|
||||
checkVariableValues(workspace, newName, type, id2);
|
||||
// The old variable should have been deleted.
|
||||
var variable = workspace.getVariableById(id1);
|
||||
assertNull(variable);
|
||||
|
||||
// There should only be one variable left.
|
||||
assertEquals(1, workspace.getAllVariables().length);
|
||||
|
||||
// References should have the correct names.
|
||||
var block_var_name_1 = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
var block_var_name_2 = workspace.topBlocks_[1].getVarModels()[0].name;
|
||||
assertEquals(newName, block_var_name_1);
|
||||
assertEquals(newName, block_var_name_2);
|
||||
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
function test_renameVariable_TwoVariablesDifferentType() {
|
||||
// Expect the rename to succeed, because variables with different types are
|
||||
// allowed to have the same name.
|
||||
workspaceTest_setUp();
|
||||
createTwoVariablesAndBlocks(workspace);
|
||||
|
||||
var newName = 'name2';
|
||||
workspace.renameVariableById('id1', newName);
|
||||
|
||||
checkVariableValues(workspace, newName, 'type1', 'id1');
|
||||
checkVariableValues(workspace, newName, 'type2', 'id2');
|
||||
|
||||
// References shoul have the correct names.
|
||||
var block_var_name_1 = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
var block_var_name_2 = workspace.topBlocks_[1].getVarModels()[0].name;
|
||||
assertEquals(newName, block_var_name_1);
|
||||
assertEquals(newName, block_var_name_2);
|
||||
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
function test_renameVariable_OldCase() {
|
||||
// Rename a variable with a single reference. Update only the capitalization.
|
||||
workspaceTest_setUp();
|
||||
var newName = 'Name1';
|
||||
|
||||
createVariableAndBlock(workspace);
|
||||
|
||||
workspace.renameVariableById('id1', newName);
|
||||
checkVariableValues(workspace, newName, 'type1', 'id1');
|
||||
var variable = workspace.getVariableById('id1');
|
||||
assertNotEquals('name1', variable.name);
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
function test_renameVariable_TwoVariablesAndOldCase() {
|
||||
// Test renaming a variable to an in-use name, but with different
|
||||
// capitalization. The new capitalization should apply everywhere.
|
||||
|
||||
// TODO (fenichel): What about different capitalization but also different
|
||||
// types?
|
||||
workspaceTest_setUp();
|
||||
var oldName = 'name1';
|
||||
var oldCase = 'Name2';
|
||||
var newName = 'name2';
|
||||
|
||||
var id1 = 'id1';
|
||||
var id2 = 'id2';
|
||||
|
||||
var type = 'type1';
|
||||
|
||||
workspace.createVariable(oldName, type, id1);
|
||||
workspace.createVariable(oldCase, type, id2);
|
||||
createMockVarBlock(workspace, id1);
|
||||
createMockVarBlock(workspace, id2);
|
||||
|
||||
workspace.renameVariableById(id1, newName);
|
||||
|
||||
checkVariableValues(workspace, newName, type, id2);
|
||||
|
||||
// The old variable should have been deleted.
|
||||
var variable = workspace.getVariableById(id1);
|
||||
assertNull(variable);
|
||||
|
||||
// There should only be one variable left.
|
||||
assertEquals(1, workspace.getAllVariables().length);
|
||||
|
||||
// Blocks should now use the new capitalization.
|
||||
var block_var_name_1 = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
var block_var_name_2 = workspace.topBlocks_[1].getVarModels()[0].name;
|
||||
assertEquals(newName, block_var_name_1);
|
||||
assertEquals(newName, block_var_name_2);
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
|
||||
function test_deleteVariableById_Trivial() {
|
||||
workspaceTest_setUp();
|
||||
createTwoVariablesAndBlocks(workspace);
|
||||
|
||||
workspace.deleteVariableById('id1');
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
var variable = workspace.getVariableById('id1');
|
||||
var block_var_name = workspace.topBlocks_[0].getVarModels()[0].name;
|
||||
assertNull(variable);
|
||||
assertEquals('name2', block_var_name);
|
||||
workspaceTest_tearDown();
|
||||
}
|
||||
381
node_modules/node-blockly/blockly/tests/jsunit/workspace_undo_redo_test.js
generated
vendored
Normal file
381
node_modules/node-blockly/blockly/tests/jsunit/workspace_undo_redo_test.js
generated
vendored
Normal file
@@ -0,0 +1,381 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Tests for Blockly.Workspace.undo.
|
||||
* @author marisaleung@google.com (Marisa Leung)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.events.EventHandler');
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.events');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
|
||||
var workspace;
|
||||
var mockControl_;
|
||||
var savedFireFunc = Blockly.Events.fire;
|
||||
|
||||
function temporary_fireEvent(event) {
|
||||
if (!Blockly.Events.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
Blockly.Events.FIRE_QUEUE_.push(event);
|
||||
Blockly.Events.fireNow_();
|
||||
}
|
||||
|
||||
function undoRedoTest_setUp() {
|
||||
defineGetVarBlock();
|
||||
workspace = new Blockly.Workspace();
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
Blockly.Events.fire = temporary_fireEvent;
|
||||
}
|
||||
|
||||
function undoRedoTest_tearDown() {
|
||||
undefineGetVarBlock();
|
||||
mockControl_.$tearDown();
|
||||
workspace.dispose();
|
||||
Blockly.Events.fire = savedFireFunc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the top block with the given index contains a variable with
|
||||
* the given name.
|
||||
* @param {number} blockIndex The index of the top block.
|
||||
* @param {string} name The expected name of the variable in the block.
|
||||
*/
|
||||
function undoRedoTest_checkBlockVariableName(blockIndex, name) {
|
||||
var blockVarName = workspace.topBlocks_[blockIndex].getVarModels()[0].name;
|
||||
assertEquals(name, blockVarName);
|
||||
}
|
||||
|
||||
function createTwoVarsEmptyType() {
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
workspace.createVariable('name2', '', 'id2');
|
||||
}
|
||||
|
||||
function createTwoVarsDifferentTypes() {
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.createVariable('name2', 'type2', 'id2');
|
||||
}
|
||||
|
||||
function test_undoCreateVariable_Trivial() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsDifferentTypes();
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
assertNull(workspace.getVariableById('id2'));
|
||||
workspace.undo();
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
assertNull(workspace.getVariableById('id2'));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_redoAndUndoCreateVariable_Trivial() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsDifferentTypes();
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
|
||||
// Expect that variable 'id2' is recreated
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
|
||||
// Expect that variable 'id1' is recreated
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
assertNull(workspace.getVariableById('id2'));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoDeleteVariable_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsDifferentTypes();
|
||||
workspace.deleteVariableById('id1');
|
||||
workspace.deleteVariableById('id2');
|
||||
|
||||
workspace.undo();
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoDeleteVariable_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
|
||||
createTwoVariablesAndBlocks(workspace);
|
||||
|
||||
workspace.deleteVariableById('id1');
|
||||
workspace.deleteVariableById('id2');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name2');
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name2');
|
||||
undoRedoTest_checkBlockVariableName(1, 'name1');
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_redoAndUndoDeleteVariable_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
|
||||
createTwoVarsDifferentTypes();
|
||||
|
||||
workspace.deleteVariableById('id1');
|
||||
workspace.deleteVariableById('id2');
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
// Expect that both variables are deleted
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
assertNull(workspace.getVariableById('id2'));
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
// Expect that variable 'id2' is recreated
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_redoAndUndoDeleteVariable_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
|
||||
createTwoVariablesAndBlocks(workspace);
|
||||
|
||||
workspace.deleteVariableById('id1');
|
||||
workspace.deleteVariableById('id2');
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
// Expect that both variables are deleted
|
||||
assertEquals(0, workspace.topBlocks_.length);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
assertNull(workspace.getVariableById('id2'));
|
||||
|
||||
workspace.undo();
|
||||
workspace.undo();
|
||||
workspace.undo(true);
|
||||
// Expect that variable 'id2' is recreated
|
||||
undoRedoTest_checkBlockVariableName(0, 'name2');
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_redoAndUndoDeleteVariableTwice_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
workspace.createVariable('name1', 'type1', 'id1');
|
||||
workspace.deleteVariableById('id1');
|
||||
workspace.deleteVariableById('id1');
|
||||
|
||||
// Check the undoStack only recorded one delete event.
|
||||
var undoStack = workspace.undoStack_;
|
||||
assertEquals('var_delete', undoStack[undoStack.length-1].type);
|
||||
assertNotEquals('var_delete', undoStack[undoStack.length-2].type);
|
||||
|
||||
// undo delete
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
|
||||
// redo delete
|
||||
workspace.undo(true);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
|
||||
// redo delete, nothing should happen
|
||||
workspace.undo(true);
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_redoAndUndoDeleteVariableTwice_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
var id = 'id1';
|
||||
workspace.createVariable('name1', 'type1', id);
|
||||
createMockVarBlock(workspace, id);
|
||||
workspace.deleteVariableById(id);
|
||||
workspace.deleteVariableById(id);
|
||||
|
||||
// Check the undoStack only recorded one delete event.
|
||||
var undoStack = workspace.undoStack_;
|
||||
assertEquals('var_delete', undoStack[undoStack.length-1].type);
|
||||
assertEquals('delete', undoStack[undoStack.length-2].type);
|
||||
assertNotEquals('var_delete', undoStack[undoStack.length-3].type);
|
||||
|
||||
// undo delete
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name1');
|
||||
checkVariableValues(workspace, 'name1', 'type1', id);
|
||||
|
||||
// redo delete
|
||||
workspace.undo(true);
|
||||
assertEquals(0, workspace.topBlocks_.length);
|
||||
assertNull(workspace.getVariableById(id));
|
||||
|
||||
// redo delete, nothing should happen
|
||||
workspace.undo(true);
|
||||
assertEquals(0, workspace.topBlocks_.length);
|
||||
assertNull(workspace.getVariableById(id));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_OneExists_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
workspace.renameVariableById('id1', 'name2');
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'name2', '', 'id1');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_OneExists_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
workspace.renameVariableById('id1', 'name2');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name1');
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'name2', '', 'id1');
|
||||
undoRedoTest_checkBlockVariableName(0, 'name2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_BothExist_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsEmptyType();
|
||||
workspace.renameVariableById('id1', 'name2');
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
checkVariableValues(workspace, 'name2', '', 'id2');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'name2', '', 'id2');
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_BothExist_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsEmptyType();
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
createMockVarBlock(workspace, 'id2');
|
||||
workspace.renameVariableById('id1', 'name2');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name1');
|
||||
undoRedoTest_checkBlockVariableName(1, 'name2');
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
checkVariableValues(workspace, 'name2', '', 'id2');
|
||||
|
||||
workspace.undo(true);
|
||||
undoRedoTest_checkBlockVariableName(0, 'name2');
|
||||
undoRedoTest_checkBlockVariableName(1, 'name2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_BothExistCaseChange_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsEmptyType();
|
||||
workspace.renameVariableById('id1', 'Name2');
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
checkVariableValues(workspace, 'name2', '', 'id2');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'Name2', '', 'id2');
|
||||
assertNull(workspace.getVariable('name1'));
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_BothExistCaseChange_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
createTwoVarsEmptyType();
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
createMockVarBlock(workspace, 'id2');
|
||||
workspace.renameVariableById('id1', 'Name2');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name1');
|
||||
undoRedoTest_checkBlockVariableName(1, 'name2');
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
checkVariableValues(workspace, 'name2', '', 'id2');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'Name2', '', 'id2');
|
||||
assertNull(workspace.getVariableById('id1'));
|
||||
undoRedoTest_checkBlockVariableName(0, 'Name2');
|
||||
undoRedoTest_checkBlockVariableName(1, 'Name2');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_OnlyCaseChange_NoBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
workspace.renameVariableById('id1', 'Name1');
|
||||
|
||||
workspace.undo();
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'Name1', '', 'id1');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
|
||||
function test_undoRedoRenameVariable_OnlyCaseChange_WithBlocks() {
|
||||
undoRedoTest_setUp();
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
createMockVarBlock(workspace, 'id1');
|
||||
workspace.renameVariableById('id1', 'Name1');
|
||||
|
||||
workspace.undo();
|
||||
undoRedoTest_checkBlockVariableName(0, 'name1');
|
||||
checkVariableValues(workspace, 'name1', '', 'id1');
|
||||
|
||||
workspace.undo(true);
|
||||
checkVariableValues(workspace, 'Name1', '', 'id1');
|
||||
undoRedoTest_checkBlockVariableName(0, 'Name1');
|
||||
undoRedoTest_tearDown();
|
||||
}
|
||||
402
node_modules/node-blockly/blockly/tests/jsunit/xml_test.js
generated
vendored
Normal file
402
node_modules/node-blockly/blockly/tests/jsunit/xml_test.js
generated
vendored
Normal file
@@ -0,0 +1,402 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2014 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.require('goog.testing');
|
||||
goog.require('goog.testing.MockControl');
|
||||
|
||||
var mockControl_;
|
||||
var workspace;
|
||||
var XML_TEXT = ['<xml xmlns="http://www.w3.org/1999/xhtml">',
|
||||
' <block type="controls_repeat_ext" inline="true" x="21" y="23">',
|
||||
' <value name="TIMES">',
|
||||
' <block type="math_number">',
|
||||
' <field name="NUM">10</field>',
|
||||
' </block>',
|
||||
' </value>',
|
||||
' <statement name="DO">',
|
||||
' <block type="variables_set" inline="true">',
|
||||
' <field name="VAR">item</field>',
|
||||
' <value name="VALUE">',
|
||||
' <block type="lists_create_empty"></block>',
|
||||
' </value>',
|
||||
' <next>',
|
||||
' <block type="text_print" inline="false">',
|
||||
' <value name="TEXT">',
|
||||
' <block type="text">',
|
||||
' <field name="TEXT">Hello</field>',
|
||||
' </block>',
|
||||
' </value>',
|
||||
' </block>',
|
||||
' </next>',
|
||||
' </block>',
|
||||
' </statement>',
|
||||
' </block>',
|
||||
'</xml>'].join('\n');
|
||||
|
||||
function xmlTest_setUp() {
|
||||
workspace = new Blockly.Workspace();
|
||||
mockControl_ = new goog.testing.MockControl();
|
||||
}
|
||||
|
||||
function xmlTest_setUpWithMockBlocks() {
|
||||
xmlTest_setUp();
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
'type': 'field_variable_test_block',
|
||||
'message0': '%1',
|
||||
'args0': [
|
||||
{
|
||||
'type': 'field_variable',
|
||||
'name': 'VAR',
|
||||
'variable': 'item'
|
||||
}
|
||||
]
|
||||
}]);
|
||||
}
|
||||
|
||||
function xmlTest_tearDown() {
|
||||
mockControl_.$tearDown();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function xmlTest_tearDownWithMockBlocks() {
|
||||
xmlTest_tearDown();
|
||||
delete Blockly.Blocks.field_variable_test_block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the values of the non variable field dom.
|
||||
* @param {!Element} fieldDom The xml dom of the non variable field.
|
||||
* @param {!string} name The expected name of the variable.
|
||||
* @param {!string} text The expected text of the variable.
|
||||
*/
|
||||
function xmlTest_checkNonVariableField(fieldDom, name, text) {
|
||||
assertEquals(text, fieldDom.textContent);
|
||||
assertEquals(name, fieldDom.getAttribute('name'));
|
||||
assertNull(fieldDom.getAttribute('id'));
|
||||
assertNull(fieldDom.getAttribute('variabletype'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the values of the variable field DOM.
|
||||
* @param {!Element} fieldDom The xml dom of the variable field.
|
||||
* @param {!string} name The expected name of the variable.
|
||||
* @param {!string} type The expected type of the variable.
|
||||
* @param {!string} id The expected id of the variable.
|
||||
* @param {!string} text The expected text of the variable.
|
||||
*/
|
||||
function xmlTest_checkVariableFieldDomValues(fieldDom, name, type, id, text) {
|
||||
assertEquals(name, fieldDom.getAttribute('name'));
|
||||
assertEquals(type, fieldDom.getAttribute('variabletype'));
|
||||
assertEquals(id, fieldDom.getAttribute('id'));
|
||||
assertEquals(text, fieldDom.textContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the values of the variable DOM.
|
||||
* @param {!Element} variableDom The xml dom of the variable.
|
||||
* @param {!string} type The expected type of the variable.
|
||||
* @param {!string} id The expected id of the variable.
|
||||
* @param {!string} text The expected text of the variable.
|
||||
*/
|
||||
function xmlTest_checkVariableDomValues(variableDom, type, id, text) {
|
||||
assertEquals(type, variableDom.getAttribute('type'));
|
||||
assertEquals(id, variableDom.getAttribute('id'));
|
||||
assertEquals(text, variableDom.textContent);
|
||||
}
|
||||
|
||||
function test_textToDom() {
|
||||
var dom = Blockly.Xml.textToDom(XML_TEXT);
|
||||
assertEquals('XML tag', 'xml', dom.nodeName);
|
||||
assertEquals('Block tags', 6, dom.getElementsByTagName('block').length);
|
||||
}
|
||||
|
||||
function test_domToText() {
|
||||
var dom = Blockly.Xml.textToDom(XML_TEXT);
|
||||
var text = Blockly.Xml.domToText(dom);
|
||||
assertEquals('Round trip', XML_TEXT.replace(/\s+/g, ''),
|
||||
text.replace(/\s+/g, ''));
|
||||
}
|
||||
|
||||
function test_domToWorkspace_BackwardCompatibility() {
|
||||
// Expect that workspace still loads without serialized variables.
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '1']);
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <block type="field_variable_test_block" id="block_id">' +
|
||||
' <field name="VAR">name1</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 1, workspace.getAllBlocks().length);
|
||||
checkVariableValues(workspace, 'name1', '', '1');
|
||||
} finally {
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_domToWorkspace_VariablesAtTop() {
|
||||
// Expect that unused variables are preserved.
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <variables>' +
|
||||
' <variable type="type1" id="id1">name1</variable>' +
|
||||
' <variable type="type2" id="id2">name2</variable>' +
|
||||
' <variable type="" id="id3">name3</variable>' +
|
||||
' </variables>' +
|
||||
' <block type="field_variable_test_block">' +
|
||||
' <field name="VAR" id="id3" variabletype="">name3</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 1, workspace.getAllBlocks().length);
|
||||
checkVariableValues(workspace, 'name1', 'type1', 'id1');
|
||||
checkVariableValues(workspace, 'name2', 'type2', 'id2');
|
||||
checkVariableValues(workspace, 'name3', '', 'id3');
|
||||
} finally {
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_domToWorkspace_VariablesAtTop_DuplicateVariablesTag() {
|
||||
// Expect thrown Error because of duplicate 'variables' tag
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <variables>' +
|
||||
' </variables>' +
|
||||
' <variables>' +
|
||||
' </variables>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
fail();
|
||||
}
|
||||
catch (e) {
|
||||
// expected
|
||||
} finally {
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_domToWorkspace_VariablesAtTop_MissingType() {
|
||||
// Expect thrown error when a variable tag is missing the type attribute.
|
||||
workspace = new Blockly.Workspace();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <variables>' +
|
||||
' <variable id="id1">name1</variable>' +
|
||||
' </variables>' +
|
||||
' <block type="field_variable_test_block">' +
|
||||
' <field name="VAR" id="id1" variabletype="">name3</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_domToWorkspace_VariablesAtTop_MismatchBlockType() {
|
||||
// Expect thrown error when the serialized type of a variable does not match
|
||||
// the type of a variable field that references it.
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml>' +
|
||||
' <variables>' +
|
||||
' <variable type="type1" id="id1">name1</variable>' +
|
||||
' </variables>' +
|
||||
' <block type="field_variable_test_block">' +
|
||||
' <field name="VAR" id="id1" variabletype="">name1</field>' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.domToWorkspace(dom, workspace);
|
||||
fail();
|
||||
} catch (e) {
|
||||
// expected
|
||||
} finally {
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_domToPrettyText() {
|
||||
var dom = Blockly.Xml.textToDom(XML_TEXT);
|
||||
var text = Blockly.Xml.domToPrettyText(dom);
|
||||
assertEquals('Round trip', XML_TEXT.replace(/\s+/g, ''),
|
||||
text.replace(/\s+/g, ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the that appendDomToWorkspace works in a headless mode.
|
||||
* Also see test_appendDomToWorkspace() in workspace_svg_test.js.
|
||||
*/
|
||||
function test_appendDomToWorkspace() {
|
||||
Blockly.Blocks.test_block = {
|
||||
init: function() {
|
||||
this.jsonInit({
|
||||
message0: 'test',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="http://www.w3.org/1999/xhtml">' +
|
||||
' <block type="test_block" inline="true" x="21" y="23">' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
workspace = new Blockly.Workspace();
|
||||
Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 1, workspace.getAllBlocks().length);
|
||||
var newBlockIds = Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 2, workspace.getAllBlocks().length);
|
||||
assertEquals('Number of new block ids',1,newBlockIds.length);
|
||||
} finally {
|
||||
delete Blockly.Blocks.test_block;
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockToDom_fieldToDom_trivial() {
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
// TODO (#1199): make a similar test where the variable is given a non-empty
|
||||
// type.f
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
var block = new Blockly.Block(workspace, 'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('id1');
|
||||
var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
xmlTest_checkVariableFieldDomValues(resultFieldDom, 'VAR', '', 'id1',
|
||||
'name1');
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_blockToDom_fieldToDom_defaultCase() {
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '1']);
|
||||
try {
|
||||
workspace.createVariable('name1');
|
||||
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('1');
|
||||
Blockly.Events.enable();
|
||||
|
||||
var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
// Expect type is '' and id is '1' since we don't specify type and id.
|
||||
xmlTest_checkVariableFieldDomValues(resultFieldDom, 'VAR', '', '1', 'name1');
|
||||
} finally {
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
function test_blockToDom_fieldToDom_notAFieldVariable() {
|
||||
Blockly.defineBlocksWithJsonArray([{
|
||||
"type": "field_angle_test_block",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "field_angle",
|
||||
"name": "VAR",
|
||||
"angle": 90
|
||||
}
|
||||
],
|
||||
}]);
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
var block = new Blockly.Block(workspace, 'field_angle_test_block');
|
||||
var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0];
|
||||
xmlTest_checkNonVariableField(resultFieldDom, 'VAR', '90');
|
||||
delete Blockly.Blocks.field_angle_block;
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_variablesToDom_oneVariable() {
|
||||
xmlTest_setUp();
|
||||
setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']);
|
||||
|
||||
workspace.createVariable('name1');
|
||||
var resultDom = Blockly.Xml.variablesToDom(workspace.getAllVariables());
|
||||
assertEquals(1, resultDom.children.length);
|
||||
var resultVariableDom = resultDom.children[0];
|
||||
assertEquals('name1', resultVariableDom.textContent);
|
||||
assertEquals('', resultVariableDom.getAttribute('type'));
|
||||
assertEquals('1', resultVariableDom.getAttribute('id'));
|
||||
xmlTest_tearDown();
|
||||
}
|
||||
|
||||
function test_variablesToDom_twoVariables_oneBlock() {
|
||||
xmlTest_setUpWithMockBlocks();
|
||||
|
||||
workspace.createVariable('name1', '', 'id1');
|
||||
workspace.createVariable('name2', 'type2', 'id2');
|
||||
// If events are enabled during block construction, it will create a default
|
||||
// variable.
|
||||
Blockly.Events.disable();
|
||||
var block = new Blockly.Block(workspace, 'field_variable_test_block');
|
||||
block.inputList[0].fieldRow[0].setValue('id1');
|
||||
Blockly.Events.enable();
|
||||
|
||||
var resultDom = Blockly.Xml.variablesToDom(workspace.getAllVariables());
|
||||
assertEquals(2, resultDom.children.length);
|
||||
xmlTest_checkVariableDomValues(resultDom.children[0], '', 'id1',
|
||||
'name1');
|
||||
xmlTest_checkVariableDomValues(resultDom.children[1], 'type2', 'id2',
|
||||
'name2');
|
||||
xmlTest_tearDownWithMockBlocks();
|
||||
}
|
||||
|
||||
function test_variablesToDom_noVariables() {
|
||||
xmlTest_setUp();
|
||||
workspace.createVariable('name1');
|
||||
var resultDom = Blockly.Xml.variablesToDom(workspace.getAllVariables());
|
||||
assertEquals(1, resultDom.children.length);
|
||||
xmlTest_tearDown();
|
||||
}
|
||||
|
||||
function test_variableFieldXml_caseSensitive() {
|
||||
var id = 'testId';
|
||||
var type = 'testType';
|
||||
var name = 'testName';
|
||||
|
||||
var mockVariableModel = {
|
||||
type: type,
|
||||
name: name,
|
||||
getId: function() {
|
||||
return id;
|
||||
}
|
||||
};
|
||||
|
||||
var generatedXml =
|
||||
Blockly.Variables.generateVariableFieldXmlString(mockVariableModel);
|
||||
var goldenXml =
|
||||
'<field name="VAR"' +
|
||||
' id="' + id + '"' +
|
||||
' variabletype="' + type + '"' +
|
||||
'>' + name + '</field>';
|
||||
assertEquals(goldenXml, generatedXml);
|
||||
}
|
||||
464
node_modules/node-blockly/blockly/tests/multi_playground.html
generated
vendored
Normal file
464
node_modules/node-blockly/blockly/tests/multi_playground.html
generated
vendored
Normal file
@@ -0,0 +1,464 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Multi-toolbox Playground</title>
|
||||
<script src="../blockly_uncompressed.js"></script>
|
||||
<script src="../msg/messages.js"></script>
|
||||
<script src="../blocks/logic.js"></script>
|
||||
<script src="../blocks/loops.js"></script>
|
||||
<script src="../blocks/math.js"></script>
|
||||
<script src="../blocks/text.js"></script>
|
||||
<script src="../blocks/lists.js"></script>
|
||||
<script src="../blocks/colour.js"></script>
|
||||
<script src="../blocks/variables.js"></script>
|
||||
<script src="../blocks/procedures.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
var options = {
|
||||
comments: true,
|
||||
collapse: true,
|
||||
disable: true,
|
||||
maxBlocks: Infinity,
|
||||
media: '../media/',
|
||||
oneBasedIndex: true,
|
||||
readOnly: false,
|
||||
//rtl: false,
|
||||
scrollbars: true,
|
||||
trashcan: true,
|
||||
//toolbox: null,
|
||||
//horizontalLayout: false,
|
||||
//toolboxPosition: 'start',
|
||||
zoom: {
|
||||
controls: true,
|
||||
wheel: false,
|
||||
startScale: 1.0,
|
||||
maxScale: 4,
|
||||
minScale: 0.25,
|
||||
scaleSpeed: 1.1
|
||||
}
|
||||
};
|
||||
|
||||
function start() {
|
||||
var match = location.search.match(/toolbox=([^&]+)/);
|
||||
var toolbox =
|
||||
document.getElementById('toolbox-' + (match ? match[1] : 'categories'));
|
||||
document.forms.options.elements.toolbox.selectedIndex =
|
||||
Number(toolbox.getElementsByTagName('category').length == 0);
|
||||
startBlocklyInstance('VertStartLTR', false, false, 'start', toolbox);
|
||||
startBlocklyInstance('VertStartRTL', true, false, 'start', toolbox);
|
||||
|
||||
startBlocklyInstance('VertEndLTR', false, false, 'end', toolbox);
|
||||
startBlocklyInstance('VertEndRTL', true, false, 'end', toolbox);
|
||||
|
||||
startBlocklyInstance('HorizontalStartLTR', false, true, 'start', toolbox);
|
||||
startBlocklyInstance('HorizontalStartRTL', true, true, 'start', toolbox);
|
||||
|
||||
startBlocklyInstance('HorizontalEndLTR', false, true, 'end', toolbox);
|
||||
startBlocklyInstance('HorizontalEndRTL', true, true, 'end', toolbox);
|
||||
}
|
||||
|
||||
function startBlocklyInstance(suffix, rtl, horizontalLayout, position,
|
||||
toolbox) {
|
||||
options.rtl = rtl;
|
||||
options.toolbox = toolbox;
|
||||
options.horizontalLayout = horizontalLayout;
|
||||
options.toolboxPosition = position;
|
||||
Blockly.inject('blocklyDiv' + suffix, options);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 140%;
|
||||
}
|
||||
|
||||
#octaweb {
|
||||
width: 100%;
|
||||
}
|
||||
#octaweb th {
|
||||
padding-top: 1em;
|
||||
width: 50%;
|
||||
}
|
||||
#octaweb td {
|
||||
width: 50%;
|
||||
}
|
||||
#octaweb td >div {
|
||||
height: 480px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="start()">
|
||||
<h1>Blockly Multi Playground</h1>
|
||||
|
||||
<form id="options">
|
||||
<select name="toolbox" onchange="document.forms.options.submit()">
|
||||
<option value="categories">Categories</option>
|
||||
<option value="simple">Simple</option>
|
||||
</select>
|
||||
</form>
|
||||
|
||||
<table id="octaweb">
|
||||
<tr>
|
||||
<th>LTR, Vertical, Start</th>
|
||||
<th>RTL, Vertical, Start</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><div id="blocklyDivVertStartLTR"></div></td>
|
||||
<td><div id="blocklyDivVertStartRTL"></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>LTR, Vertical, End</th>
|
||||
<th>RTL, Vertical, End</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><div id="blocklyDivVertEndLTR"></div></td>
|
||||
<td><div id="blocklyDivVertEndRTL"></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>LTR, Horizontal, Start</th>
|
||||
<th>RTL, Horizontal, Start</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><div id="blocklyDivHorizontalStartLTR"></div></td>
|
||||
<td><div id="blocklyDivHorizontalStartRTL"></div></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>LTR, Horizontal, End</th>
|
||||
<th>RTL, Horizontal, End</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><div id="blocklyDivHorizontalEndLTR"></div></td>
|
||||
<td><div id="blocklyDivHorizontalEndRTL"></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<xml id="toolbox-simple" style="display: none">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<!-- <block type="control_repeat"></block> -->
|
||||
<block type="logic_operation"></block>
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="logic_operation"></block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean"></block>
|
||||
<block type="logic_null" disabled="true"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</xml>
|
||||
|
||||
<xml id="toolbox-categories" style="display: none">
|
||||
<category name="Logic" colour="210">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<block type="logic_operation"></block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean"></block>
|
||||
<block type="logic_null" disabled="true"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</category>
|
||||
<category name="Loops" colour="120">
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_repeat" disabled="true"></block>
|
||||
<block type="controls_whileUntil"></block>
|
||||
<block type="controls_for">
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_forEach"></block>
|
||||
<block type="controls_flow_statements"></block>
|
||||
</category>
|
||||
<category name="Math" colour="230">
|
||||
<block type="math_number" gap="32">
|
||||
<field name="NUM">123</field>
|
||||
</block>
|
||||
<block type="math_arithmetic">
|
||||
<value name="A">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="B">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_single">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">9</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_trig">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">45</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constant"></block>
|
||||
<block type="math_number_property">
|
||||
<value name="NUMBER_TO_CHECK">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_round">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">3.1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_on_list"></block>
|
||||
<block type="math_modulo">
|
||||
<value name="DIVIDEND">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">64</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="DIVISOR">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constrain">
|
||||
<value name="VALUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="LOW">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="HIGH">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_int">
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_float"></block>
|
||||
</category>
|
||||
<category name="Text" colour="160">
|
||||
<block type="text"></block>
|
||||
<block type="text_join"></block>
|
||||
<block type="text_append">
|
||||
<value name="TEXT">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_length">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_isEmpty">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT"></field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="FIND">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_charAt">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_getSubstring">
|
||||
<value name="STRING">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_changeCase">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_trim">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_print">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_prompt_ext">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_with">
|
||||
<mutation items="0"></mutation>
|
||||
</block>
|
||||
<block type="lists_create_with"></block>
|
||||
<block type="lists_repeat">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_length"></block>
|
||||
<block type="lists_isEmpty"></block>
|
||||
<block type="lists_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getIndex">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_setIndex">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getSublist">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_split">
|
||||
<value name="DELIM">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">,</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_sort"></block>
|
||||
</category>
|
||||
<category name="Colour" colour="20">
|
||||
<block type="colour_picker"></block>
|
||||
<block type="colour_random"></block>
|
||||
<block type="colour_rgb">
|
||||
<value name="RED">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="colour_blend">
|
||||
<value name="COLOUR1">
|
||||
<shadow type="colour_picker">
|
||||
<field name="COLOUR">#ff0000</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="COLOUR2">
|
||||
<shadow type="colour_picker">
|
||||
<field name="COLOUR">#3333ff</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="RATIO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0.5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
</xml>
|
||||
</body>
|
||||
</html>
|
||||
1201
node_modules/node-blockly/blockly/tests/playground.html
generated
vendored
Normal file
1201
node_modules/node-blockly/blockly/tests/playground.html
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
39
node_modules/node-blockly/blockly/tests/playgrounds/iframe.html
generated
vendored
Normal file
39
node_modules/node-blockly/blockly/tests/playgrounds/iframe.html
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blockly <iframe> Playground</title>
|
||||
<style>
|
||||
html, body {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
h1#title {
|
||||
border: 0;
|
||||
margin: 2px;
|
||||
padding: 0;
|
||||
width: %100;
|
||||
}
|
||||
#playground-iframe {
|
||||
border: 0;
|
||||
width: %100;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var onWindowResize = function() {
|
||||
var iframe = document.getElementById('playground-iframe');
|
||||
var top = iframe.getBoundingClientRect().top;
|
||||
iframe.height = window.innerHeight - top;
|
||||
iframe.width = window.innerWidth;
|
||||
};
|
||||
window.addEventListener("resize", onWindowResize);
|
||||
window.addEventListener("load", onWindowResize);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="title">Outer Frame</h1>
|
||||
<iframe id="playground-iframe" src="../playground.html">
|
||||
</body>
|
||||
</html>
|
||||
17
node_modules/node-blockly/blockly/tests/scripts/get_chromedriver.sh
generated
vendored
Executable file
17
node_modules/node-blockly/blockly/tests/scripts/get_chromedriver.sh
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
os_name=`uname`
|
||||
chromedriver_dir="chromedriver"
|
||||
if [ ! -d $chromedriver_dir ]; then
|
||||
mkdir $chromedriver_dir
|
||||
fi
|
||||
|
||||
echo "downloading chromedriver"
|
||||
|
||||
if [[ $os_name == 'Linux' && ! -f $chromedriver_dir/chromedriver ]]; then
|
||||
cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip > tmp.zip && unzip -o tmp.zip && rm tmp.zip
|
||||
# wait until download finish
|
||||
sleep 5
|
||||
elif [[ $os_name == 'Darwin' && ! -f $chromedriver_dir/chromedriver ]]; then
|
||||
cd chromedriver && curl -L https://chromedriver.storage.googleapis.com/2.29/chromedriver_mac64.zip | tar xz
|
||||
sleep 5
|
||||
fi
|
||||
15
node_modules/node-blockly/blockly/tests/scripts/get_geckdriver.sh
generated
vendored
Executable file
15
node_modules/node-blockly/blockly/tests/scripts/get_geckdriver.sh
generated
vendored
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
os_name=`uname`
|
||||
|
||||
if [ -f geckodriver ]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "downloading gechdriver"
|
||||
|
||||
if [[ $os_name == 'Linux' ]]; then
|
||||
cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz | tar xz
|
||||
sleep 5
|
||||
elif [[ $os_name == 'Darwin' ]]; then
|
||||
cd ../ && curl -L https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-macos.tar.gz | tar xz
|
||||
sleep 5
|
||||
fi
|
||||
14
node_modules/node-blockly/blockly/tests/scripts/get_selenium.sh
generated
vendored
Executable file
14
node_modules/node-blockly/blockly/tests/scripts/get_selenium.sh
generated
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
DIR="../webdriverio-test"
|
||||
FILE=selenium-server-standalone-3.0.1.jar
|
||||
|
||||
if [ ! -d $DIR ]; then
|
||||
mkdir $DIR
|
||||
fi
|
||||
|
||||
echo "downloading selenium jar"
|
||||
|
||||
if [ ! -f $DIR/$FILE ]; then
|
||||
cd $DIR && curl -O http://selenium-release.storage.googleapis.com/3.0/selenium-server-standalone-3.0.1.jar
|
||||
sleep 5
|
||||
fi
|
||||
10
node_modules/node-blockly/blockly/tests/scripts/selenium_connect.sh
generated
vendored
Executable file
10
node_modules/node-blockly/blockly/tests/scripts/selenium_connect.sh
generated
vendored
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
#check if selenium server is up running
|
||||
pid=`lsof -ti tcp:4444`
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
kill -9 $pid
|
||||
fi
|
||||
java -jar -Dwebdriver.gecko.driver=../geckodriver -Dwebdriver.chrome.driver="chromedriver/chromedriver" ../webdriverio-test/selenium-server-standalone-3.0.1.jar &
|
||||
|
||||
8
node_modules/node-blockly/blockly/tests/scripts/setup_linux_env.sh
generated
vendored
Executable file
8
node_modules/node-blockly/blockly/tests/scripts/setup_linux_env.sh
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "${TRAVIS_OS_NAME}" == "linux" ]
|
||||
then
|
||||
export CHROME_BIN="/usr/bin/google-chrome"
|
||||
export DISPLAY=:99.0
|
||||
sh -e /etc/init.d/xvfb start &
|
||||
fi
|
||||
8
node_modules/node-blockly/blockly/tests/scripts/setup_osx_env.sh
generated
vendored
Executable file
8
node_modules/node-blockly/blockly/tests/scripts/setup_osx_env.sh
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "${TRAVIS_OS_NAME}" == "osx" ]
|
||||
then
|
||||
brew cask install google-chrome
|
||||
sudo Xvfb :99 -ac -screen 0 1024x768x8 &
|
||||
export CHROME_BIN="/Applications/Google Chrome.app"
|
||||
fi
|
||||
23
node_modules/node-blockly/blockly/tests/scripts/test_setup.sh
generated
vendored
Executable file
23
node_modules/node-blockly/blockly/tests/scripts/test_setup.sh
generated
vendored
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
EXIT_STATUS=0
|
||||
|
||||
function check_command {
|
||||
"$@"
|
||||
local STATUS=$?
|
||||
if [ $STATUS -ne 0 ]; then
|
||||
echo "error with $1 ($STATUS)" >&2
|
||||
EXIT_STATUS=$STATUS
|
||||
fi
|
||||
}
|
||||
|
||||
check_command tests/scripts/get_geckdriver.sh
|
||||
sleep 5
|
||||
check_command tests/scripts/get_selenium.sh
|
||||
sleep 5
|
||||
check_command tests/scripts/get_chromedriver.sh
|
||||
sleep 10
|
||||
check_command tests/scripts/selenium_connect.sh
|
||||
sleep 10
|
||||
|
||||
exit $EXIT_STATUS
|
||||
399
node_modules/node-blockly/blockly/tests/workspace_svg/index.html
generated
vendored
Normal file
399
node_modules/node-blockly/blockly/tests/workspace_svg/index.html
generated
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Blockly Workspace SVG testing</title>
|
||||
<script src="../../blockly_uncompressed.js"></script>
|
||||
<script>goog.require('goog.testing.jsunit');</script>
|
||||
<script src="../../msg/messages.js"></script>
|
||||
<script src="../../blocks/logic.js"></script>
|
||||
<script src="../../blocks/loops.js"></script>
|
||||
<script src="../../blocks/math.js"></script>
|
||||
<script src="../../blocks/text.js"></script>
|
||||
<script src="../../blocks/lists.js"></script>
|
||||
<script src="../../blocks/colour.js"></script>
|
||||
<script src="../../blocks/variables.js"></script>
|
||||
<script src="../../blocks/procedures.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
background-color: #fff;
|
||||
font-family: sans-serif;
|
||||
overflow: hidden;
|
||||
}
|
||||
h1 {
|
||||
font-weight: normal;
|
||||
font-size: 140%;
|
||||
}
|
||||
#blocklyDiv {
|
||||
float: right;
|
||||
height: 95%;
|
||||
width: 70%;
|
||||
}
|
||||
#importExport {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.ioLabel>.blocklyFlyoutLabelText {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="blocklyDiv"></div>
|
||||
|
||||
<h1>Blockly Workspace testing</h1>
|
||||
<script src="workspace_svg_test.js"></script>
|
||||
|
||||
<xml id="toolbox-simple" style="display: none">
|
||||
<block type="controls_ifelse"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<!-- <block type="control_repeat"></block> -->
|
||||
<block type="logic_operation"></block>
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="logic_operation"></block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean"></block>
|
||||
<block type="logic_null" disabled="true"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</xml>
|
||||
|
||||
<xml id="toolbox-categories" style="display: none">
|
||||
<category name="Logic" colour="210">
|
||||
<block type="controls_if"></block>
|
||||
<block type="logic_compare"></block>
|
||||
<block type="logic_operation"></block>
|
||||
<block type="logic_negate"></block>
|
||||
<block type="logic_boolean"></block>
|
||||
<block type="logic_null" disabled="true"></block>
|
||||
<block type="logic_ternary"></block>
|
||||
</category>
|
||||
<category name="Loops" colour="120">
|
||||
<block type="controls_repeat_ext">
|
||||
<value name="TIMES">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_repeat" disabled="true"></block>
|
||||
<block type="controls_whileUntil"></block>
|
||||
<block type="controls_for">
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="BY">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="controls_forEach"></block>
|
||||
<block type="controls_flow_statements"></block>
|
||||
</category>
|
||||
<category name="Math" colour="230">
|
||||
<block type="math_number" gap="32"></block>
|
||||
<block type="math_arithmetic">
|
||||
<value name="A">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="B">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_single">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">9</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_trig">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">45</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constant"></block>
|
||||
<block type="math_number_property">
|
||||
<value name="NUMBER_TO_CHECK">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_round">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">3.1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_on_list"></block>
|
||||
<block type="math_modulo">
|
||||
<value name="DIVIDEND">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">64</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="DIVISOR">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">10</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_constrain">
|
||||
<value name="VALUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="LOW">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="HIGH">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_int">
|
||||
<value name="FROM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">1</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="math_random_float"></block>
|
||||
</category>
|
||||
<category name="Text" colour="160">
|
||||
<block type="text"></block>
|
||||
<block type="text_join"></block>
|
||||
<block type="text_append">
|
||||
<value name="TEXT">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_length">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_isEmpty">
|
||||
<value name="VALUE">
|
||||
<shadow type="text">
|
||||
<field name="TEXT"></field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
<value name="FIND">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_charAt">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_getSubstring">
|
||||
<value name="STRING">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">text</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_changeCase">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_trim">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_count">
|
||||
<value name="SUB">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
<value name="TEXT">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_replace">
|
||||
<value name="FROM">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
<value name="TO">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
<value name="TEXT">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_reverse">
|
||||
<value name="TEXT">
|
||||
<shadow type="text"></shadow>
|
||||
</value>
|
||||
</block>
|
||||
<label text="Input/Output:" web-class="ioLabel"></label>
|
||||
<block type="text_print">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="text_prompt_ext">
|
||||
<value name="TEXT">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">abc</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<category name="Lists" colour="260">
|
||||
<block type="lists_create_with">
|
||||
<mutation items="0"></mutation>
|
||||
</block>
|
||||
<block type="lists_create_with"></block>
|
||||
<block type="lists_repeat">
|
||||
<value name="NUM">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_length"></block>
|
||||
<block type="lists_isEmpty"></block>
|
||||
<block type="lists_indexOf">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getIndex">
|
||||
<value name="VALUE">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_setIndex">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_getSublist">
|
||||
<value name="LIST">
|
||||
<block type="variables_get">
|
||||
<field name="VAR">list</field>
|
||||
</block>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_split">
|
||||
<value name="DELIM">
|
||||
<shadow type="text">
|
||||
<field name="TEXT">,</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="lists_sort"></block>
|
||||
<block type="lists_reverse"></block>
|
||||
</category>
|
||||
<category name="Colour" colour="20">
|
||||
<block type="colour_picker"></block>
|
||||
<block type="colour_random"></block>
|
||||
<block type="colour_rgb">
|
||||
<value name="RED">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">100</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="GREEN">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">50</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="BLUE">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
<block type="colour_blend">
|
||||
<value name="COLOUR1">
|
||||
<shadow type="colour_picker">
|
||||
<field name="COLOUR">#ff0000</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="COLOUR2">
|
||||
<shadow type="colour_picker">
|
||||
<field name="COLOUR">#3333ff</field>
|
||||
</shadow>
|
||||
</value>
|
||||
<value name="RATIO">
|
||||
<shadow type="math_number">
|
||||
<field name="NUM">0.5</field>
|
||||
</shadow>
|
||||
</value>
|
||||
</block>
|
||||
</category>
|
||||
<sep></sep>
|
||||
<category name="Variables" colour="330" custom="VARIABLE"></category>
|
||||
<category name="Functions" colour="290" custom="PROCEDURE"></category>
|
||||
</xml>
|
||||
</body>
|
||||
</html>
|
||||
95
node_modules/node-blockly/blockly/tests/workspace_svg/workspace_svg_test.js
generated
vendored
Normal file
95
node_modules/node-blockly/blockly/tests/workspace_svg/workspace_svg_test.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @license
|
||||
* Blockly Tests
|
||||
*
|
||||
* Copyright 2017 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
function helper_createWorkspaceWithToolbox() {
|
||||
var toolbox = document.getElementById('toolbox-categories');
|
||||
return Blockly.inject('blocklyDiv', {toolbox: toolbox});
|
||||
}
|
||||
|
||||
function test_createWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
workspace.dispose();
|
||||
}
|
||||
|
||||
function test_emptyWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
try {
|
||||
assertEquals('Empty workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Empty workspace (4).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Empty workspace (5).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Empty workspace (6).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function test_flatWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
var blockA, blockB;
|
||||
try {
|
||||
blockA = workspace.newBlock('');
|
||||
assertEquals('One block workspace (1).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (2).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (3).', 1, workspace.getAllBlocks().length);
|
||||
blockB = workspace.newBlock('');
|
||||
assertEquals('Two block workspace (1).', 2, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Two block workspace (2).', 2, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Two block workspace (3).', 2, workspace.getAllBlocks().length);
|
||||
blockA.dispose();
|
||||
assertEquals('One block workspace (4).', 1, workspace.getTopBlocks(true).length);
|
||||
assertEquals('One block workspace (5).', 1, workspace.getTopBlocks(false).length);
|
||||
assertEquals('One block workspace (6).', 1, workspace.getAllBlocks().length);
|
||||
workspace.clear();
|
||||
assertEquals('Cleared workspace (1).', 0, workspace.getTopBlocks(true).length);
|
||||
assertEquals('Cleared workspace (2).', 0, workspace.getTopBlocks(false).length);
|
||||
assertEquals('Cleared workspace (3).', 0, workspace.getAllBlocks().length);
|
||||
} finally {
|
||||
blockB && blockB.dispose();
|
||||
blockA && blockA.dispose();
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/** Tests the alignment of appendDomToWorkspace with WorkspaceSvg. */
|
||||
function test_appendDomToWorkspace() {
|
||||
var workspace = helper_createWorkspaceWithToolbox();
|
||||
try {
|
||||
var dom = Blockly.Xml.textToDom(
|
||||
'<xml xmlns="http://www.w3.org/1999/xhtml">' +
|
||||
' <block type="math_random_float" inline="true" x="21" y="23">' +
|
||||
' </block>' +
|
||||
'</xml>');
|
||||
Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 1, workspace.getAllBlocks().length);
|
||||
Blockly.Xml.appendDomToWorkspace(dom, workspace);
|
||||
assertEquals('Block count', 2, workspace.getAllBlocks().length);
|
||||
var blocks = workspace.getAllBlocks();
|
||||
assertEquals('Block 1 position x',21,blocks[0].getRelativeToSurfaceXY().x);
|
||||
assertEquals('Block 1 position y',23,blocks[0].getRelativeToSurfaceXY().y);
|
||||
assertEquals('Block 2 position x',21,blocks[1].getRelativeToSurfaceXY().x);
|
||||
assertEquals('Block 2 position y',23 + blocks[0].getHeightWidth().height + Blockly.BlockSvg.SEP_SPACE_Y,blocks[1].getRelativeToSurfaceXY().y);
|
||||
} finally {
|
||||
workspace.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user