From c7aee7fd25665ea298c9b32fb04dcf9a7b51dd51 Mon Sep 17 00:00:00 2001 From: euzuro Date: Thu, 1 Jun 2006 10:52:22 +0000 Subject: [PATCH] add OpenLayers.Util.upperCaseObject() function and test git-svn-id: http://svn.openlayers.org/trunk/openlayers@491 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Util.js | 17 +++++++++++++++++ tests/test_Util.html | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 7736e719bb..9102a2916e 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -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. diff --git a/tests/test_Util.html b/tests/test_Util.html index e2499bbb16..b1a026a1df 100644 --- a/tests/test_Util.html +++ b/tests/test_Util.html @@ -353,8 +353,40 @@ } else { t.ok(true); } - + } + + 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"); + } + // -->