Adding procedure tests and handling procedures instantiated without name (#4428)

* Expand procedure tests and fix bug with default ids

* Add tests

* Remove xml_procedures_test.js and add non-overlapping test cases into procedures_test.js
This commit is contained in:
Monica Kozbial
2020-11-06 11:48:48 -08:00
committed by GitHub
parent f71a1b9c76
commit dd0d5aee53
6 changed files with 560 additions and 333 deletions

View File

@@ -28,7 +28,8 @@ Blockly.Blocks['procedures_defnoreturn'] = {
* @this {Blockly.Block}
*/
init: function() {
var nameField = new Blockly.FieldTextInput('',
var initName = Blockly.Procedures.findLegalName('', this);
var nameField = new Blockly.FieldTextInput(initName,
Blockly.Procedures.rename);
nameField.setSpellcheck(false);
this.appendDummyInput()
@@ -405,7 +406,8 @@ Blockly.Blocks['procedures_defreturn'] = {
* @this {Blockly.Block}
*/
init: function() {
var nameField = new Blockly.FieldTextInput('',
var initName = Blockly.Procedures.findLegalName('', this);
var nameField = new Blockly.FieldTextInput(initName,
Blockly.Procedures.rename);
nameField.setSpellcheck(false);
this.appendDummyInput()
@@ -592,7 +594,7 @@ Blockly.Blocks['procedures_callnoreturn'] = {
*/
init: function() {
this.appendDummyInput('TOPROW')
.appendField(this.id, 'NAME');
.appendField('', 'NAME');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setStyle('procedure_blocks');
@@ -873,8 +875,13 @@ Blockly.Blocks['procedures_callnoreturn'] = {
block.appendChild(mutation);
var field = Blockly.utils.xml.createElement('field');
field.setAttribute('name', 'NAME');
field.appendChild(Blockly.utils.xml.createTextNode(
this.getProcedureCall()));
var callName = this.getProcedureCall();
if (!callName) {
// Rename if name is empty string.
callName = Blockly.Procedures.findLegalName('', this);
this.renameProcedure('', callName);
}
field.appendChild(Blockly.utils.xml.createTextNode(callName));
block.appendChild(field);
xml.appendChild(block);
Blockly.Xml.domToWorkspace(xml, this.workspace);
@@ -955,6 +962,7 @@ Blockly.Blocks['procedures_callreturn'] = {
// Tooltip is set in domToMutation.
this.setHelpUrl(Blockly.Msg['PROCEDURES_CALLRETURN_HELPURL']);
this.arguments_ = [];
this.argumentVarModels_ = [];
this.quarkConnections_ = {};
this.quarkIds_ = null;
this.previousEnabledState_ = true;