diff --git a/core/variables.js b/core/variables.js index cec5132fe..4b7e0669e 100644 --- a/core/variables.js +++ b/core/variables.js @@ -466,9 +466,6 @@ Blockly.Variables.generateVariableFieldXmlString = function(variableModel) { // The variable name may be user input, so it may contain characters that // need to be escaped to create valid XML. var typeString = variableModel.type; - if (typeString == '') { - typeString = '\'\''; - } var text = '' + goog.string.htmlEscape(variableModel.name) + ''; diff --git a/tests/mocha/xml_test.js b/tests/mocha/xml_test.js index f0801c625..82bd0c73c 100644 --- a/tests/mocha/xml_test.js +++ b/tests/mocha/xml_test.js @@ -287,6 +287,138 @@ suite('XML', function() { }); }); suite('Deserialization', function() { + suite('Dynamic Category Blocks', function() { + test('Untyped Variables', function() { + Blockly.defineBlocksWithJsonArray([{ + "type": "variables_get", + "message0": "%1", + "args0": [ + { + "type": "field_variable", + "name": "VAR", + } + ] + }, + { + "type": "variables_set", + "message0": "%1 %2", + "args0": [ + { + "type": "field_variable", + "name": "VAR" + }, + { + "type": "input_value", + "name": "VALUE" + } + ] + }, + { + "type": "math_change", + "message0": "%1 %2", + "args0": [ + { + "type": "field_variable", + "name": "VAR", + }, + { + "type": "input_value", + "name": "DELTA", + "check": "Number" + } + ] + }, + { + "type": "math_number", + "message0": "%1", + "args0": [{ + "type": "field_number", + "name": "NUM", + "value": 0 + }], + "output": "Number" + }]); + this.workspace.createVariable('name1', '', 'id1'); + var blocksArray = Blockly.Variables.flyoutCategoryBlocks(this.workspace); + try { + for (var i = 0, xml; xml = blocksArray[i]; i++) { + Blockly.Xml.domToBlock(xml, this.workspace); + } + } finally { + delete Blockly.Blocks['variables_get']; + delete Blockly.Blocks['variables_set']; + delete Blockly.Blocks['math_change']; + delete Blockly.Blocks['math_number']; + } + }); + test('Typed Variables', function() { + Blockly.defineBlocksWithJsonArray([{ + "type": "variables_get", + "message0": "%1", + "args0": [ + { + "type": "field_variable", + "name": "VAR", + } + ] + }, + { + "type": "variables_set", + "message0": "%1 %2", + "args0": [ + { + "type": "field_variable", + "name": "VAR" + }, + { + "type": "input_value", + "name": "VALUE" + } + ] + }, + { + "type": "math_change", + "message0": "%1 %2", + "args0": [ + { + "type": "field_variable", + "name": "VAR", + }, + { + "type": "input_value", + "name": "DELTA", + "check": "Number" + } + ] + }, + { + "type": "math_number", + "message0": "%1", + "args0": [{ + "type": "field_number", + "name": "NUM", + "value": 0 + }], + "output": "Number" + }]); + + this.workspace.createVariable('name1', 'String', 'id1'); + this.workspace.createVariable('name2', 'Number', 'id2'); + this.workspace.createVariable('name3', 'Colour', 'id3'); + var blocksArray = Blockly.VariablesDynamic + .flyoutCategoryBlocks(this.workspace); + try { + for (var i = 0, xml; xml = blocksArray[i]; i++) { + Blockly.Xml.domToBlock(xml, this.workspace); + } + } finally { + delete Blockly.Blocks['variables_get']; + delete Blockly.Blocks['variables_set']; + delete Blockly.Blocks['math_change']; + delete Blockly.Blocks['math_number']; + } + }); + }); }); });