diff --git a/core/field_variable.js b/core/field_variable.js index 6a32ff61b..6fbae1c42 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -154,7 +154,7 @@ Blockly.FieldVariable.dropdownCreate = function() { } options.push([Blockly.Msg.RENAME_VARIABLE, Blockly.RENAME_VARIABLE_ID]); options.push([Blockly.Msg.DELETE_VARIABLE.replace('%1', name), - Blockly.DELETE_VARIABLE_ID]); + Blockly.DELETE_VARIABLE_ID]); return options; }; diff --git a/core/variable_model.js b/core/variable_model.js index e84a76132..b5ec897ac 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -81,8 +81,10 @@ Blockly.VariableModel.prototype.getId = function() { * A custom compare function for the VariableModel objects. * @param {Blockly.VariableModel} var1 First variable to compare. * @param {Blockly.VariableModel} var2 Second variable to compare. + * @return {number} -1 if name of var1 is less than name of var2, 0 if equal, + * and 1 if greater. * @package */ Blockly.VariableModel.compareByName = function(var1, var2) { - return goog.string.caseInsensitiveCompare(var1.name, var2.name) + return goog.string.caseInsensitiveCompare(var1.name, var2.name); }; diff --git a/core/workspace.js b/core/workspace.js index 78a3cd5d0..fa99869d6 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -215,8 +215,8 @@ Blockly.Workspace.prototype.updateVariableStore = function(clear) { // Get variable model with the used variable name. var tempVar = this.getVariable(name); if (tempVar) { - varList.push({'name': tempVar.name, 'type': tempVar.type, - 'id': tempVar.getId()}); + varList.push({'name': tempVar.name, 'type': tempVar.type, + 'id': tempVar.getId()}); } else { varList.push({'name': name, 'type': null, 'id': null}); @@ -248,7 +248,7 @@ Blockly.Workspace.prototype.renameVariableInternal_ = function(variable, newName // If they are different types, throw an error. if (variable && newVariable && variable.type != newVariable.type) { - throw Error('Variable "' + oldName + '" is type "' + variable.type + + throw Error('Variable "' + variable.name + '" is type "' + variable.type + '" and variable "' + newName + '" is type "' + newVariable.type + '". Both must be the same type.'); } @@ -295,7 +295,7 @@ Blockly.Workspace.prototype.renameVariable = function(oldName, newName) { Blockly.Workspace.prototype.renameVariableById = function(id, newName) { var variable = this.getVariableById(id); this.renameVariableInternal_(variable, newName); -} +}; /** * Create a variable with a given name, optional type, and optional id. diff --git a/tests/jsunit/variable_map_test.js b/tests/jsunit/variable_map_test.js index 7911a33a8..fbb33209b 100644 --- a/tests/jsunit/variable_map_test.js +++ b/tests/jsunit/variable_map_test.js @@ -103,7 +103,7 @@ function test_createVariableTrivial() { function test_createVariableAlreadyExists() { // Expect that when the variable already exists, the variableMap_ is unchanged. variableMapTest_setUp(); - var var_1 = variable_map.createVariable('name1', 'type1', 'id1'); + variable_map.createVariable('name1', 'type1', 'id1'); // Assert there is only one variable in the variable_map. var keys = Object.keys(variable_map.variableMap_); diff --git a/tests/jsunit/variable_model_test.js b/tests/jsunit/variable_model_test.js index 9a2d2ac3a..e1245233e 100644 --- a/tests/jsunit/variable_model_test.js +++ b/tests/jsunit/variable_model_test.js @@ -75,4 +75,4 @@ function testInit_OnlyNameProvided() { assertEquals('', variable.type); assertNotNull(variable.id_); variableTest_tearDown(); -} \ No newline at end of file +} diff --git a/tests/jsunit/workspace_test.js b/tests/jsunit/workspace_test.js index bf4618a86..986a20560 100644 --- a/tests/jsunit/workspace_test.js +++ b/tests/jsunit/workspace_test.js @@ -26,14 +26,14 @@ var workspace; var mockControl_; var saved_msg = Blockly.Msg.DELETE_VARIABLE; Blockly.defineBlocksWithJsonArray([{ - "type": "get_var_block", - "message0": "%1", - "args0": [ - { - "type": "field_variable", - "name": "VAR", - } - ] + "type": "get_var_block", + "message0": "%1", + "args0": [ + { + "type": "field_variable", + "name": "VAR", + } + ] }]); function workspaceTest_setUp() { @@ -220,7 +220,7 @@ function test_getBlockById() { } function test_deleteVariable_InternalTrivial() { - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var var_1 = workspace.createVariable('name1', 'type1', 'id1'); workspace.createVariable('name2', 'type2', 'id2'); createMockBlock('name1'); @@ -309,7 +309,7 @@ function test_updateVariableStore_ClearAndOneInUse() { } function test_addTopBlock_TrivialFlyoutIsTrue() { - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); workspace.isFlyout = true; var block = createMockBlock(); workspace.removeTopBlock(block); @@ -395,7 +395,7 @@ function test_renameVariable_NoBlocks() { function test_renameVariable_SameNameNoBlocks() { // Expect 'renameVariable' to create new variable with newName. - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var name = 'name1'; workspace.createVariable(name, 'type1', 'id1'); @@ -406,7 +406,7 @@ function test_renameVariable_SameNameNoBlocks() { function test_renameVariable_OnlyOldNameBlockExists() { // Expect 'renameVariable' to change oldName variable name to newName. - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var oldName = 'name1'; var newName = 'name2'; workspace.createVariable(oldName, 'type1', 'id1'); @@ -424,7 +424,7 @@ function test_renameVariable_OnlyOldNameBlockExists() { function test_renameVariable_TwoVariablesSameType() { // Expect 'renameVariable' to change oldName variable name to newName. // Expect oldName block name to change to newName - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var oldName = 'name1'; var newName = 'name2'; workspace.createVariable(oldName, 'type1', 'id1'); @@ -445,7 +445,7 @@ function test_renameVariable_TwoVariablesSameType() { function test_renameVariable_TwoVariablesDifferentType() { // Expect triggered error because of different types - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var oldName = 'name1'; var newName = 'name2'; workspace.createVariable(oldName, 'type1', 'id1'); @@ -478,14 +478,14 @@ function test_renameVariable_OldCase() { workspace.renameVariable(oldCase, newName); workspaceTest_checkVariableValues(newName, 'type1', 'id1'); - var result_oldCase = workspace.getVariable(oldCase).name + var result_oldCase = workspace.getVariable(oldCase).name; assertNotEquals(oldCase, result_oldCase); workspaceTest_tearDownWithMockBlocks(); } function test_renameVariable_TwoVariablesAndOldCase() { // Expect triggered error because of different types - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var oldName = 'name1'; var oldCase = 'Name2'; var newName = 'name2'; @@ -513,7 +513,7 @@ function test_renameVariable_TwoVariablesAndOldCase() { function test_renameVariableById_TwoVariablesSameType() { // Expect 'renameVariableById' to change oldName variable name to newName. // Expect oldName block name to change to newName - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); var oldName = 'name1'; var newName = 'name2'; workspace.createVariable(oldName, 'type1', 'id1'); @@ -523,7 +523,7 @@ function test_renameVariableById_TwoVariablesSameType() { workspace.renameVariableById('id1', newName); workspaceTest_checkVariableValues(newName, 'type1', 'id2'); - var variable = workspace.getVariable(oldName) + var variable = workspace.getVariable(oldName); var block_var_name_1 = workspace.topBlocks_[0].getVars()[0]; var block_var_name_2 = workspace.topBlocks_[1].getVars()[0]; assertNull(variable); @@ -533,7 +533,7 @@ function test_renameVariableById_TwoVariablesSameType() { } function test_deleteVariable_Trivial() { - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); workspace.createVariable('name1', 'type1', 'id1'); workspace.createVariable('name2', 'type1', 'id2'); createMockBlock('name1'); @@ -549,7 +549,7 @@ function test_deleteVariable_Trivial() { } function test_deleteVariableById_Trivial() { - workspaceTest_setUpWithMockBlocks() + workspaceTest_setUpWithMockBlocks(); workspace.createVariable('name1', 'type1', 'id1'); workspace.createVariable('name2', 'type1', 'id2'); createMockBlock('name1'); diff --git a/tests/jsunit/xml_test.js b/tests/jsunit/xml_test.js index c7fc2b379..12f3ced71 100644 --- a/tests/jsunit/xml_test.js +++ b/tests/jsunit/xml_test.js @@ -308,17 +308,17 @@ function test_appendDomToWorkspace() { } function test_blockToDom_fieldToDom_trivial() { - xmlTest_setUpWithMockBlocks() + xmlTest_setUpWithMockBlocks(); workspace.createVariable('name1', 'type1', 'id1'); var block = new Blockly.Block(workspace, 'field_variable_test_block'); block.inputList[0].fieldRow[0].setValue('name1'); var resultFieldDom = Blockly.Xml.blockToDom(block).childNodes[0]; xmlTest_checkVariableFieldDomValues(resultFieldDom, 'VAR', 'type1', 'id1', 'name1') - xmlTest_tearDownWithMockBlocks() + xmlTest_tearDownWithMockBlocks(); } function test_blockToDom_fieldToDom_defaultCase() { - xmlTest_setUpWithMockBlocks() + xmlTest_setUpWithMockBlocks(); var mockGenUid = mockControl_.createMethodMock(Blockly.utils, 'genUid'); mockGenUid().$returns('1'); mockGenUid().$replay(); @@ -327,8 +327,8 @@ function test_blockToDom_fieldToDom_defaultCase() { block.inputList[0].fieldRow[0].setValue('name1'); 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') - xmlTest_tearDownWithMockBlocks() + xmlTest_checkVariableFieldDomValues(resultFieldDom, 'VAR', '', '1', 'name1'); + xmlTest_tearDownWithMockBlocks(); } function test_blockToDom_fieldToDom_notAFieldVariable() { @@ -343,12 +343,12 @@ function test_blockToDom_fieldToDom_notAFieldVariable() { } ], }]); - xmlTest_setUpWithMockBlocks() + 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() + xmlTest_tearDownWithMockBlocks(); } function test_variablesToDom_oneVariable() {