@@ -30,6 +30,25 @@ suite('Variables', function () {
3030 'variableTypes' : [ '' , 'type1' , 'type2' ] ,
3131 } ,
3232 ] ,
33+ 'output' : null ,
34+ } ,
35+ // Block for variable setter.
36+ {
37+ 'type' : 'set_var_block' ,
38+ 'message0' : '%{BKY_VARIABLES_SET}' ,
39+ 'args0' : [
40+ {
41+ 'type' : 'field_variable' ,
42+ 'name' : 'VAR' ,
43+ 'variableTypes' : [ '' , 'type1' , 'type2' ] ,
44+ } ,
45+ {
46+ 'type' : 'input_value' ,
47+ 'name' : 'VALUE' ,
48+ } ,
49+ ] ,
50+ 'previousStatement' : null ,
51+ 'nextStatement' : null ,
3352 } ,
3453 ] ) ;
3554 this . variableMap = this . workspace . getVariableMap ( ) ;
@@ -59,6 +78,21 @@ suite('Variables', function () {
5978 return block ;
6079 }
6180
81+ test ( 'can be deleted when two connected blocks reference the same variable' , function ( ) {
82+ const getter = new Blockly . Block ( this . workspace , 'get_var_block' ) ;
83+ getter . getField ( 'VAR' ) . setValue ( '1' ) ;
84+
85+ const setter = new Blockly . Block ( this . workspace , 'set_var_block' ) ;
86+ setter . getField ( 'VAR' ) . setValue ( '1' ) ;
87+ setter . getInput ( 'VALUE' ) . connection . connect ( getter . outputConnection ) ;
88+
89+ this . variableMap . deleteVariable ( this . variableMap . getVariableById ( '1' ) ) ;
90+ // Both blocks should have been deleted.
91+ assert . equal ( 0 , this . workspace . getAllBlocks ( false ) . length ) ;
92+ // The variable itself should have been deleted.
93+ assert . equal ( this . variableMap . getVariableById ( '1' ) , undefined ) ;
94+ } ) ;
95+
6296 suite ( 'allUsedVarModels' , function ( ) {
6397 test ( 'All used' , function ( ) {
6498 createTestVarBlock ( this . workspace , '1' ) ;
0 commit comments