Change variableType to variabletype in xml.

Scratch-blocks version of blockly pr #1422
This commit is contained in:
Paul Kaplan 2017-11-06 10:19:49 -05:00
parent f8fbd2cc76
commit 807743d20f
4 changed files with 42 additions and 17 deletions

View file

@ -179,7 +179,7 @@ Blockly.DataCategory.addHideVariable = function(xmlList, variable) {
*/
Blockly.DataCategory.addAddToList = function(xmlList, variable) {
// <block type="data_addtolist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="ITEM">
// <shadow type="text">
// <field name="TEXT">thing</field>
@ -197,7 +197,7 @@ Blockly.DataCategory.addAddToList = function(xmlList, variable) {
*/
Blockly.DataCategory.addDeleteOfList = function(xmlList, variable) {
// <block type="data_deleteoflist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="INDEX">
// <shadow type="math_integer">
// <field name="NUM">1</field>
@ -215,7 +215,7 @@ Blockly.DataCategory.addDeleteOfList = function(xmlList, variable) {
*/
Blockly.DataCategory.addInsertAtList = function(xmlList, variable) {
// <block type="data_insertatlist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="INDEX">
// <shadow type="math_integer">
// <field name="NUM">1</field>
@ -238,7 +238,7 @@ Blockly.DataCategory.addInsertAtList = function(xmlList, variable) {
*/
Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) {
// <block type="data_replaceitemoflist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="INDEX">
// <shadow type="math_integer">
// <field name="NUM">1</field>
@ -261,7 +261,7 @@ Blockly.DataCategory.addReplaceItemOfList = function(xmlList, variable) {
*/
Blockly.DataCategory.addItemOfList = function(xmlList, variable) {
// <block type="data_itemoflist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="INDEX">
// <shadow type="math_integer">
// <field name="NUM">1</field>
@ -279,7 +279,7 @@ Blockly.DataCategory.addItemOfList = function(xmlList, variable) {
*/
Blockly.DataCategory.addLengthOfList = function(xmlList, variable) {
// <block type="data_lengthoflist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// </block>
Blockly.DataCategory.addBlock(xmlList, variable, 'data_lengthoflist', 'LIST');
};
@ -291,7 +291,7 @@ Blockly.DataCategory.addLengthOfList = function(xmlList, variable) {
*/
Blockly.DataCategory.addListContainsItem = function(xmlList, variable) {
// <block type="data_listcontainsitem">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// <value name="ITEM">
// <shadow type="text">
// <field name="TEXT">thing</field>
@ -309,7 +309,7 @@ Blockly.DataCategory.addListContainsItem = function(xmlList, variable) {
*/
Blockly.DataCategory.addShowList = function(xmlList, variable) {
// <block type="data_showlist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// </block>
Blockly.DataCategory.addBlock(xmlList, variable, 'data_showlist', 'LIST');
};
@ -321,7 +321,7 @@ Blockly.DataCategory.addShowList = function(xmlList, variable) {
*/
Blockly.DataCategory.addHideList = function(xmlList, variable) {
// <block type="data_hidelist">
// <field name="LIST" variableType="list" id="">variablename</field>
// <field name="LIST" variabletype="list" id="">variablename</field>
// </block>
Blockly.DataCategory.addBlock(xmlList, variable, 'data_hidelist', 'LIST');
};

View file

@ -302,7 +302,7 @@ Blockly.Variables.generateVariableFieldXml_ = function(variableModel, opt_name)
// to be escaped to create valid XML.
var element = goog.dom.createDom('field');
element.setAttribute('name', opt_name || 'VARIABLE');
element.setAttribute('variableType', variableModel.type);
element.setAttribute('variabletype', variableModel.type);
element.setAttribute('id', variableModel.getId());
element.textContent = variableModel.name;

View file

@ -115,7 +115,7 @@ Blockly.Xml.blockToDom = function(block, opt_noId) {
var variable = block.workspace.getVariable(field.getValue());
if (variable) {
container.setAttribute('id', variable.getId());
container.setAttribute('variableType', variable.type);
container.setAttribute('variabletype', variable.type);
}
}
element.appendChild(container);
@ -613,7 +613,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
// TODO (marisaleung): When we change setValue and getValue to
// interact with id's instead of names, update this so that we get
// the variable based on id instead of textContent.
var type = xmlChild.getAttribute('variableType') || '';
var type = xmlChild.getAttribute('variabletype') || '';
var variable = workspace.getVariable(text);
if (!variable) {
variable = workspace.createVariable(text, type,

View file

@ -106,7 +106,7 @@ function xmlTest_checkNonVariableField(fieldDom, name, text) {
assertEquals(text, fieldDom.textContent);
assertEquals(name, fieldDom.getAttribute('name'));
assertNull(fieldDom.getAttribute('id'));
assertNull(fieldDom.getAttribute('variableType'));
assertNull(fieldDom.getAttribute('variabletype'));
}
/**
@ -119,7 +119,7 @@ function xmlTest_checkNonVariableField(fieldDom, name, text) {
*/
function xmlTest_checkVariableFieldDomValues(fieldDom, name, type, id, text) {
assertEquals(name, fieldDom.getAttribute('name'));
assertEquals(type, fieldDom.getAttribute('variableType'));
assertEquals(type, fieldDom.getAttribute('variabletype'));
assertEquals(id, fieldDom.getAttribute('id'));
assertEquals(text, fieldDom.textContent);
}
@ -181,7 +181,7 @@ function test_domToWorkspace_VariablesAtTop() {
' <variable type="" id="id3">name3</variable>' +
' </variables>' +
' <block type="field_variable_test_block">' +
' <field name="VAR" id="id3" variableType="">name3</field>' +
' <field name="VAR" id="id3" variabletype="">name3</field>' +
' </block>' +
'</xml>');
Blockly.Xml.domToWorkspace(dom, workspace);
@ -225,7 +225,7 @@ function test_domToWorkspace_VariablesAtTop_MissingType() {
' <variable id="id1">name1</variable>' +
' </variables>' +
' <block type="field_variable_test_block">' +
' <field name="VAR" id="id1" variableType="">name3</field>' +
' <field name="VAR" id="id1" variabletype="">name3</field>' +
' </block>' +
'</xml>');
Blockly.Xml.domToWorkspace(dom, workspace);
@ -248,7 +248,7 @@ function test_domToWorkspace_VariablesAtTop_MismatchBlockType() {
' <variable type="type1" id="id1">name1</variable>' +
' </variables>' +
' <block type="field_variable_test_block">' +
' <field name="VAR" id="id1" variableType="">name1</field>' +
' <field name="VAR" id="id1" variabletype="">name1</field>' +
' </block>' +
'</xml>');
Blockly.Xml.domToWorkspace(dom, workspace);
@ -408,3 +408,28 @@ function test_fieldIsNotSerialized() {
xmlTest_tearDownWithMockBlocks();
}
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.generateVariableFieldXml_(mockVariableModel);
// The field contains this XML tag as a result of how we're generating this
// XML. This is not desirable, but the goal of this test is to make sure
// we're preserving case-sensitivity.
var xmlns = 'xmlns="http://www.w3.org/1999/xhtml"';
var goldenXml =
'<field ' + xmlns + ' name="VARIABLE"' +
' variabletype="' + type + '"' +
' id="' + id + '">' + name + '</field>';
assertEquals(goldenXml, generatedXml);
}