Allow variables of different types to share the same name.

This commit is contained in:
Rachel Fenichel
2017-11-29 14:37:34 -08:00
parent 0cb5dfc437
commit c825e60813
10 changed files with 214 additions and 111 deletions

View File

@@ -43,18 +43,24 @@ function variableMapTest_tearDown() {
variable_map = null;
}
function test_getVariable_Trivial() {
function test_getVariable_ByNameAndType() {
variableMapTest_setUp();
var var_1 = variable_map.createVariable('name1', 'type1', 'id1');
var var_2 = variable_map.createVariable('name2', 'type1', 'id2');
var var_3 = variable_map.createVariable('name3', 'type2', 'id3');
var result_1 = variable_map.getVariable('name1');
var result_2 = variable_map.getVariable('name2');
var result_3 = variable_map.getVariable('name3');
var result_1 = variable_map.getVariable('name1', 'type1');
var result_2 = variable_map.getVariable('name2', 'type1');
var result_3 = variable_map.getVariable('name3', 'type2');
// Searching by name + type is correct.
assertEquals(var_1, result_1);
assertEquals(var_2, result_2);
assertEquals(var_3, result_3);
// Searching only by name defaults to the '' type.
assertNull(variable_map.getVariable('name1'));
assertNull(variable_map.getVariable('name2'));
assertNull(variable_map.getVariable('name3'));
variableMapTest_tearDown();
}
@@ -105,7 +111,7 @@ function test_createVariableAlreadyExists() {
var varMapLength = variable_map.variableMap_[keys[0]].length;
assertEquals(1, varMapLength);
variable_map.createVariable('name1');
variable_map.createVariable('name1', 'type1');
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
// Check that the size of the variableMap_ did not change.
keys = Object.keys(variable_map.variableMap_);
@@ -115,6 +121,26 @@ function test_createVariableAlreadyExists() {
variableMapTest_tearDown();
}
function test_createVariableNameAlreadyExists() {
// Expect that when a variable with the same name but a different type already
// exists, the new variable is created.
variableMapTest_setUp();
variable_map.createVariable('name1', 'type1', 'id1');
// Assert there is only one variable in the variable_map.
var keys = Object.keys(variable_map.variableMap_);
assertEquals(1, keys.length);
var varMapLength = variable_map.variableMap_[keys[0]].length;
assertEquals(1, varMapLength);
variable_map.createVariable('name1', 'type2', 'id2');
checkVariableValues(variable_map, 'name1', 'type1', 'id1');
checkVariableValues(variable_map, 'name1', 'type2', 'id2');
// Check that the size of the variableMap_ did change.
keys = Object.keys(variable_map.variableMap_);
assertEquals(2, keys.length);
variableMapTest_tearDown();
}
function test_createVariableNullAndUndefinedType() {
variableMapTest_setUp();
variable_map.createVariable('name1', null, 'id1');