From c58553b7ba29f4433cdf539151e68f6cd50ace82 Mon Sep 17 00:00:00 2001 From: marisaleung Date: Fri, 9 Jun 2017 15:22:33 -0700 Subject: [PATCH] Create utility function for checking variable values. --- tests/jsunit/event_test.js | 22 ++----- tests/jsunit/test_utilities.js | 16 +++++ tests/jsunit/variable_map_test.js | 30 +++------ tests/jsunit/workspace_test.js | 52 ++++++---------- tests/jsunit/workspace_undo_redo_test.js | 78 ++++++++++-------------- tests/jsunit/xml_test.js | 22 ++----- 6 files changed, 83 insertions(+), 137 deletions(-) diff --git a/tests/jsunit/event_test.js b/tests/jsunit/event_test.js index 82b95cc46..8d302472d 100644 --- a/tests/jsunit/event_test.js +++ b/tests/jsunit/event_test.js @@ -121,20 +121,6 @@ function checkExactEventValues(event, values) { } } -/** - * Check if a variable with the given values exists. - * @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 eventTest_checkVariableValues(name, type, id) { - var variable = workspace.getVariableById(id); - assertNotUndefined(variable); - assertEquals(name, variable.name); - assertEquals(type, variable.type); - assertEquals(id, variable.getId()); -} - function test_create_constructor() { eventTest_setUpWithMockBlocks(); setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1']); @@ -293,7 +279,7 @@ function test_varCreate_runForward() { var event = Blockly.Events.fromJson(json, workspace); assertNull(workspace.getVariableById('id1')); event.run(true); - eventTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); eventTest_tearDown(); } @@ -357,7 +343,7 @@ function test_varDelete_runBackwards() { var event = Blockly.Events.fromJson(json, workspace); assertNull(workspace.getVariableById('id1')); event.run(false); - eventTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); eventTest_tearDown(); } @@ -400,7 +386,7 @@ function test_varRename_runForward() { var event = new Blockly.Events.VarRename(variable, 'name2'); event.run(true); assertNull(workspace.getVariable('name1')); - eventTest_checkVariableValues('name2', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type1', 'id1'); eventTest_tearDown(); } @@ -410,6 +396,6 @@ function test_varBackard_runForward() { var event = new Blockly.Events.VarRename(variable, 'name2'); event.run(false); assertNull(workspace.getVariable('name2')); - eventTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); eventTest_tearDown(); } diff --git a/tests/jsunit/test_utilities.js b/tests/jsunit/test_utilities.js index 75cdf3c77..6a80a3549 100644 --- a/tests/jsunit/test_utilities.js +++ b/tests/jsunit/test_utilities.js @@ -73,3 +73,19 @@ function setUpMockMethod(mockControl, scope, funcName, parameters, 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()); +} diff --git a/tests/jsunit/variable_map_test.js b/tests/jsunit/variable_map_test.js index 30cd9283a..51141cffc 100644 --- a/tests/jsunit/variable_map_test.js +++ b/tests/jsunit/variable_map_test.js @@ -38,20 +38,6 @@ function variableMapTest_tearDown() { variable_map = null; } -/** - * Check if a variable with the given values exists. - * @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 variableMapTest_checkVariableValues(name, type, id) { - var variable = variable_map.getVariable(name); - assertNotUndefined(variable); - assertEquals(name, variable.name); - assertEquals(type, variable.type); - assertEquals(id, variable.getId()); -} - function test_getVariable_Trivial() { variableMapTest_setUp(); var var_1 = variable_map.createVariable('name1', 'type1', 'id1'); @@ -99,7 +85,7 @@ function test_getVariableById_NotFound() { function test_createVariableTrivial() { variableMapTest_setUp(); variable_map.createVariable('name1', 'type1', 'id1'); - variableMapTest_checkVariableValues('name1', 'type1', 'id1') + checkVariableValues(variable_map, 'name1', 'type1', 'id1'); variableMapTest_tearDown(); } @@ -115,7 +101,7 @@ function test_createVariableAlreadyExists() { assertEquals(1, varMapLength); variable_map.createVariable('name1'); - variableMapTest_checkVariableValues('name1', 'type1', 'id1'); + 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); @@ -129,8 +115,8 @@ function test_createVariableNullAndUndefinedType() { variable_map.createVariable('name1', null, 'id1'); variable_map.createVariable('name2', undefined, 'id2'); - variableMapTest_checkVariableValues('name1', '', 'id1'); - variableMapTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(variable_map, 'name1', '', 'id1'); + checkVariableValues(variable_map, 'name2', '', 'id2'); variableMapTest_tearDown(); } @@ -139,7 +125,7 @@ function test_createVariableNullId() { setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']); try { variable_map.createVariable('name1', 'type1', null); - variableMapTest_checkVariableValues('name1', 'type1', '1'); + checkVariableValues(variable_map, 'name1', 'type1', '1'); } finally { variableMapTest_tearDown(); @@ -151,7 +137,7 @@ function test_createVariableUndefinedId() { setUpMockMethod(mockControl_, Blockly.utils, 'genUid', null, ['1', '2']); try { variable_map.createVariable('name1', 'type1', undefined); - variableMapTest_checkVariableValues('name1', 'type1', '1'); + checkVariableValues(variable_map, 'name1', 'type1', '1'); } finally { variableMapTest_tearDown(); @@ -193,8 +179,8 @@ function test_createVariableTwoSameTypes() { variable_map.createVariable('name1', 'type1', 'id1'); variable_map.createVariable('name2', 'type1', 'id2'); - variableMapTest_checkVariableValues('name1', 'type1', 'id1'); - variableMapTest_checkVariableValues('name2', 'type1', 'id2'); + checkVariableValues(variable_map, 'name1', 'type1', 'id1'); + checkVariableValues(variable_map, 'name2', 'type1', 'id2'); variableMapTest_tearDown(); } diff --git a/tests/jsunit/workspace_test.js b/tests/jsunit/workspace_test.js index a3ab32f1c..0046d869d 100644 --- a/tests/jsunit/workspace_test.js +++ b/tests/jsunit/workspace_test.js @@ -71,20 +71,6 @@ function createMockBlock(variable_name) { return block; } -/** - * Check if a variable with the given values exists. - * @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 workspaceTest_checkVariableValues(name, type, id) { - var variable = workspace.getVariable(name); - assertNotUndefined(variable); - assertEquals(name, variable.name); - assertEquals(type, variable.type); - assertEquals(id, variable.getId()); -} - function test_emptyWorkspace() { workspaceTest_setUp(); try { @@ -198,7 +184,7 @@ function test_deleteVariable_InternalTrivial() { var variable = workspace.getVariable('name1'); var block_var_name = workspace.topBlocks_[0].getVars()[0]; assertNull(variable); - workspaceTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); assertEquals('name2', block_var_name); workspaceTest_tearDownWithMockBlocks(); } @@ -214,8 +200,8 @@ function test_updateVariableStore_TrivialNoClear() { try { workspace.updateVariableStore(); - workspaceTest_checkVariableValues('name1', 'type1', 'id1'); - workspaceTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); } finally { workspaceTest_tearDown(); @@ -230,7 +216,7 @@ function test_updateVariableStore_NameNotInvariableMap_NoClear() { try { workspace.updateVariableStore(); - workspaceTest_checkVariableValues('name1', '', '1'); + checkVariableValues(workspace, 'name1', '', '1'); } finally { workspaceTest_tearDown(); @@ -246,8 +232,8 @@ function test_updateVariableStore_ClearAndAllInUse() { try { workspace.updateVariableStore(true); - workspaceTest_checkVariableValues('name1', 'type1', 'id1'); - workspaceTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); } finally { workspaceTest_tearDown(); @@ -263,7 +249,7 @@ function test_updateVariableStore_ClearAndOneInUse() { try { workspace.updateVariableStore(true); - workspaceTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); var variabe = workspace.getVariable('name2'); assertNull(variable); } @@ -283,7 +269,7 @@ function test_addTopBlock_TrivialFlyoutIsTrue() { try { workspace.addTopBlock(block); - workspaceTest_checkVariableValues('name1', '', '1'); + checkVariableValues(workspace, 'name1', '', '1'); } finally { workspaceTest_tearDownWithMockBlocks(); @@ -338,7 +324,7 @@ function test_renameVariable_NoBlocks() { try { workspace.renameVariable(oldName, newName); - workspaceTest_checkVariableValues('name2', '', '1'); + checkVariableValues(workspace, 'name2', '', '1'); var variable = workspace.getVariable(oldName); assertNull(variable); } @@ -354,7 +340,7 @@ function test_renameVariable_SameNameNoBlocks() { workspace.createVariable(name, 'type1', 'id1'); workspace.renameVariable(name, name); - workspaceTest_checkVariableValues(name, 'type1', 'id1'); + checkVariableValues(workspace, name, 'type1', 'id1'); workspaceTest_tearDownWithMockBlocks(); } @@ -367,7 +353,7 @@ function test_renameVariable_OnlyOldNameBlockExists() { createMockBlock(oldName); workspace.renameVariable(oldName, newName); - workspaceTest_checkVariableValues(newName, 'type1', 'id1'); + checkVariableValues(workspace, newName, 'type1', 'id1'); var variable = workspace.getVariable(oldName); var block_var_name = workspace.topBlocks_[0].getVars()[0]; assertNull(variable); @@ -387,7 +373,7 @@ function test_renameVariable_TwoVariablesSameType() { createMockBlock(newName); workspace.renameVariable(oldName, newName); - workspaceTest_checkVariableValues(newName, 'type1', 'id2'); + checkVariableValues(workspace, newName, 'type1', 'id2'); 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]; @@ -413,8 +399,8 @@ function test_renameVariable_TwoVariablesDifferentType() { } catch (e) { // expected } - workspaceTest_checkVariableValues(oldName, 'type1', 'id1'); - workspaceTest_checkVariableValues(newName, 'type2', 'id2'); + checkVariableValues(workspace, oldName, 'type1', 'id1'); + checkVariableValues(workspace, newName, 'type2', 'id2'); var block_var_name_1 = workspace.topBlocks_[0].getVars()[0]; var block_var_name_2 = workspace.topBlocks_[1].getVars()[0]; assertEquals(oldName, block_var_name_1); @@ -431,7 +417,7 @@ function test_renameVariable_OldCase() { createMockBlock(oldCase); workspace.renameVariable(oldCase, newName); - workspaceTest_checkVariableValues(newName, 'type1', 'id1'); + checkVariableValues(workspace, newName, 'type1', 'id1'); var result_oldCase = workspace.getVariable(oldCase).name; assertNotEquals(oldCase, result_oldCase); workspaceTest_tearDownWithMockBlocks(); @@ -450,7 +436,7 @@ function test_renameVariable_TwoVariablesAndOldCase() { workspace.renameVariable(oldName, newName); - workspaceTest_checkVariableValues(newName, 'type1', 'id2'); + checkVariableValues(workspace, newName, 'type1', 'id2'); var variable = workspace.getVariable(oldName); var result_oldCase = workspace.getVariable(oldCase).name; var block_var_name_1 = workspace.topBlocks_[0].getVars()[0]; @@ -476,7 +462,7 @@ function test_renameVariableById_TwoVariablesSameType() { createMockBlock(newName); workspace.renameVariableById('id1', newName); - workspaceTest_checkVariableValues(newName, 'type1', 'id2'); + checkVariableValues(workspace, newName, 'type1', 'id2'); 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]; @@ -494,7 +480,7 @@ function test_deleteVariable_Trivial() { createMockBlock('name2'); workspace.deleteVariable('name1'); - workspaceTest_checkVariableValues('name2', 'type1', 'id2'); + checkVariableValues(workspace, 'name2', 'type1', 'id2'); var variable = workspace.getVariable('name1'); var block_var_name = workspace.topBlocks_[0].getVars()[0]; assertNull(variable); @@ -510,7 +496,7 @@ function test_deleteVariableById_Trivial() { createMockBlock('name2'); workspace.deleteVariableById('id1'); - workspaceTest_checkVariableValues('name2', 'type1', 'id2'); + checkVariableValues(workspace, 'name2', 'type1', 'id2'); var variable = workspace.getVariable('name1'); var block_var_name = workspace.topBlocks_[0].getVars()[0]; assertNull(variable); diff --git a/tests/jsunit/workspace_undo_redo_test.js b/tests/jsunit/workspace_undo_redo_test.js index 022b11be6..3fe5c733d 100644 --- a/tests/jsunit/workspace_undo_redo_test.js +++ b/tests/jsunit/workspace_undo_redo_test.js @@ -89,20 +89,6 @@ function createMockBlock(variableName) { return block; } -/** - * Check if a variable with the given values exists. - * @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 undoRedoTest_checkVariableValues(name, type, id) { - var variable = workspace.getVariable(name); - assertNotUndefined(variable); - assertEquals(name, variable.name); - assertEquals(type, variable.type); - assertEquals(id, variable.getId()); -} - /** * Check that the top block with the given index contains a variable with * the given name. @@ -125,7 +111,7 @@ function test_undoCreateVariable_Trivial() { workspace.createVariable('name2', 'type2', 'id2'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); assertNull(workspace.getVariableById('id2')); workspace.undo(); assertNull(workspace.getVariableById('id1')); @@ -142,15 +128,15 @@ function test_redoAndUndoCreateVariable_Trivial() { workspace.undo(true); // Expect that variable 'id2' is recreated - undoRedoTest_checkVariableValues('name1', 'type1', 'id1'); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); workspace.undo(); workspace.undo(); workspace.undo(true); // Expect that variable 'id1' is recreated - undoRedoTest_checkVariableValues('name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); assertNull(workspace.getVariableById('id2')); undoRedoTest_tearDown(); } @@ -164,11 +150,11 @@ function test_undoDeleteVariable_NoBlocks() { workspace.undo(); assertNull(workspace.getVariableById('id1')); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', 'type1', 'id1'); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); undoRedoTest_tearDown(); } @@ -184,13 +170,13 @@ function test_undoDeleteVariable_WithBlocks() { workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name2'); assertNull(workspace.getVariableById('id1')); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name2'); undoRedoTest_checkBlockVariableName(1, 'name1'); - undoRedoTest_checkVariableValues('name1', 'type1', 'id1'); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); undoRedoTest_tearDownWithMockBlocks(); } @@ -212,7 +198,7 @@ function test_redoAndUndoDeleteVariable() { workspace.undo(true); // Expect that variable 'id2' is recreated assertNull(workspace.getVariableById('id1')); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); undoRedoTest_tearDown(); } @@ -238,7 +224,7 @@ function test_redoAndUndoDeleteVariableWithBlocks() { // Expect that variable 'id2' is recreated undoRedoTest_checkBlockVariableName(0, 'name2'); assertNull(workspace.getVariableById('id1')); - undoRedoTest_checkVariableValues('name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); undoRedoTest_tearDownWithMockBlocks(); } @@ -255,7 +241,7 @@ function test_undoRedoRenameVariable_NeitherVariableExists() { assertNull(workspace.getVariableById('id2')); workspace.undo(true); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name2', '', 'id2'); undoRedoTest_tearDown(); } @@ -265,11 +251,11 @@ function test_undoRedoRenameVariable_OneExists_NoBlocks() { workspace.renameVariable('name1', 'name2'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', '', 'id1'); + checkVariableValues(workspace, 'name1', '', 'id1'); assertNull(workspace.getVariable('name2')); workspace.undo(true); - undoRedoTest_checkVariableValues('name2', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id1'); undoRedoTest_tearDown(); } @@ -281,11 +267,11 @@ function test_undoRedoRenameVariable_OneExists_WithBlocks() { workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name1'); - undoRedoTest_checkVariableValues('name1', '', 'id1'); + checkVariableValues(workspace, 'name1', '', 'id1'); assertNull(workspace.getVariable('name2')); workspace.undo(true); - undoRedoTest_checkVariableValues('name2', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id1'); undoRedoTest_checkBlockVariableName(0, 'name2'); undoRedoTest_tearDownWithMockBlocks(); } @@ -296,11 +282,11 @@ function test_undoRedoRenameVariable_BothExist_NoBlocks() { workspace.renameVariable('name1', 'name2'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', '', 'id1'); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name1', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id2'); workspace.undo(true); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name2', '', 'id2'); assertNull(workspace.getVariable('name1')); undoRedoTest_tearDown(); } @@ -315,8 +301,8 @@ function test_undoRedoRenameVariable_BothExist_WithBlocks() { workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name1'); undoRedoTest_checkBlockVariableName(1, 'name2'); - undoRedoTest_checkVariableValues('name1', '', 'id1'); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name1', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id2'); workspace.undo(true); undoRedoTest_checkBlockVariableName(0, 'name2'); @@ -330,11 +316,11 @@ function test_undoRedoRenameVariable_BothExistCaseChange_NoBlocks() { workspace.renameVariable('name1', 'Name2'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', '', 'id1'); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name1', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id2'); workspace.undo(true); - undoRedoTest_checkVariableValues('Name2', '', 'id2'); + checkVariableValues(workspace, 'Name2', '', 'id2'); assertNull(workspace.getVariable('name1')); undoRedoTest_tearDown(); } @@ -349,11 +335,11 @@ function test_undoRedoRenameVariable_BothExistCaseChange_WithBlocks() { workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name1'); undoRedoTest_checkBlockVariableName(1, 'name2'); - undoRedoTest_checkVariableValues('name1', '', 'id1'); - undoRedoTest_checkVariableValues('name2', '', 'id2'); + checkVariableValues(workspace, 'name1', '', 'id1'); + checkVariableValues(workspace, 'name2', '', 'id2'); workspace.undo(true); - undoRedoTest_checkVariableValues('Name2', '', 'id2'); + checkVariableValues(workspace, 'Name2', '', 'id2'); assertNull(workspace.getVariable('name1')); undoRedoTest_checkBlockVariableName(0, 'Name2'); undoRedoTest_checkBlockVariableName(1, 'Name2'); @@ -366,10 +352,10 @@ function test_undoRedoRenameVariable_OnlyCaseChange_NoBlocks() { workspace.renameVariable('name1', 'Name1'); workspace.undo(); - undoRedoTest_checkVariableValues('name1', '', 'id1'); + checkVariableValues(workspace, 'name1', '', 'id1'); workspace.undo(true); - undoRedoTest_checkVariableValues('Name1', '', 'id1'); + checkVariableValues(workspace, 'Name1', '', 'id1'); undoRedoTest_tearDown(); } @@ -381,10 +367,10 @@ function test_undoRedoRenameVariable_OnlyCaseChange_WithBlocks() { workspace.undo(); undoRedoTest_checkBlockVariableName(0, 'name1'); - undoRedoTest_checkVariableValues('name1', '', 'id1'); + checkVariableValues(workspace, 'name1', '', 'id1'); workspace.undo(true); - undoRedoTest_checkVariableValues('Name1', '', 'id1'); + checkVariableValues(workspace, 'Name1', '', 'id1'); undoRedoTest_checkBlockVariableName(0, 'Name1'); undoRedoTest_tearDownWithMockBlocks(); } diff --git a/tests/jsunit/xml_test.js b/tests/jsunit/xml_test.js index 255eba011..6cc65b3b1 100644 --- a/tests/jsunit/xml_test.js +++ b/tests/jsunit/xml_test.js @@ -129,20 +129,6 @@ function xmlTest_checkVariableDomValues(variableDom, type, id, text) { assertEquals(text, variableDom.textContent); } -/** - * Check if a variable with the given values exists. - * @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 xmlTest_checkVariableValues(name, type, id) { - var variable = workspace.getVariable(name); - assertNotUndefined(variable); - assertEquals(name, variable.name); - assertEquals(type, variable.type); - assertEquals(id, variable.getId()); -} - function test_textToDom() { var dom = Blockly.Xml.textToDom(XML_TEXT); assertEquals('XML tag', 'xml', dom.nodeName); @@ -169,7 +155,7 @@ function test_domToWorkspace_BackwardCompatibility() { ''); Blockly.Xml.domToWorkspace(dom, workspace); assertEquals('Block count', 1, workspace.getAllBlocks().length); - xmlTest_checkVariableValues('name1', '', '1'); + checkVariableValues(workspace, 'name1', '', '1'); } finally { xmlTest_tearDownWithMockBlocks(); } @@ -192,9 +178,9 @@ function test_domToWorkspace_VariablesAtTop() { ''); Blockly.Xml.domToWorkspace(dom, workspace); assertEquals('Block count', 1, workspace.getAllBlocks().length); - xmlTest_checkVariableValues('name1', 'type1', 'id1'); - xmlTest_checkVariableValues('name2', 'type2', 'id2'); - xmlTest_checkVariableValues('name3', '', 'id3'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + checkVariableValues(workspace, 'name2', 'type2', 'id2'); + checkVariableValues(workspace, 'name3', '', 'id3'); } finally { xmlTest_tearDownWithMockBlocks(); }