add OpenLayers.Util.upperCaseObject() function and test

git-svn-id: http://svn.openlayers.org/trunk/openlayers@491 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-06-01 10:52:22 +00:00
parent 128825886e
commit c7aee7fd25
2 changed files with 50 additions and 1 deletions

View File

@@ -785,6 +785,23 @@ OpenLayers.Util.createAlphaImageDiv = function(id, px, sz, imgURL,
};
/** Creates a new hash and copies over all the keys from the
* passed-in object, but storing them under an uppercased
* version of the key at which they were stored.
*
* @param {Object} object
*
* @returns A new Object with all the same keys but uppercased
* @type Object
*/
OpenLayers.Util.upperCaseObject = function (object) {
var uObject = new Object();
for (var key in object) {
uObject[key.toUpperCase()] = object[key];
}
return uObject;
};
/** Takes a hash and copies any keys that don't exist from
* another hash, by analogy with Object.extend() from
* Prototype.js.

View File

@@ -355,6 +355,38 @@
}
}
function test_10_Util_upperCaseObject(t) {
t.plan(8);
var aKey = "chicken";
var aValue = "pot pie";
var bKey = "blorg";
var bValue = "us maximus";
var obj = new Object();
obj[aKey] = aValue;
obj[bKey] = bValue;
var uObj = OpenLayers.Util.upperCaseObject(obj);
//make sure old object not modified
t.eq(obj[aKey], aValue, "old lowercase value still present in old obj");
t.eq(obj[bKey], bValue, "old lowercase value still present in old obj");
t.eq(obj[aKey.toUpperCase()], null, "new uppercase value not present in old obj");
t.eq(obj[bKey.toUpperCase()], null, "new uppercase value not present in old obj");
//make sure new object modified
t.eq(uObj[aKey], null, "old lowercase value not present");
t.eq(uObj[bKey], null, "old lowercase value not present");
t.eq(uObj[aKey.toUpperCase()], aValue, "new uppercase value present");
t.eq(uObj[bKey.toUpperCase()], bValue, "new uppercase value present");
}
// -->
</script>
</head>