New OpenLayers.String.format function to Format a string given a string

template and some context -- to be used within the SLD framework. Developed
by Andreas and Sr. Schaub. Thanks, guys!


git-svn-id: http://svn.openlayers.org/trunk/openlayers@5317 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-12-01 13:20:59 +00:00
parent 10cf5bfefc
commit 76fa0da3b7
2 changed files with 72 additions and 1 deletions

View File

@@ -82,7 +82,41 @@
t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)");
}
}
function test_String_format(t) {
var unchanged = [
"", "${ ", "${", " ${", "${${", "${}", "${${}}", " ${ ${",
"}", "${${} }"
]
t.plan(4 + unchanged.length);
var format = OpenLayers.String.format;
var expected;
for(var i=0; i<unchanged.length; ++i) {
expected = unchanged[i];
t.eq(format(expected), expected,
"'" + expected + "' left unchanged");
}
t.eq(format("${foo} none"),
"undefined none", "undefined properties don't bomb");
window.foo = "bar";
t.eq(format("${foo} none"),
"bar none", "window context used if none passed");
var context = {bar: "foo"};
t.eq(format("${bar} foo", context), "foo foo",
"properties accessed from context");
var context = {bar: "foo", foo: "bar"};
t.eq(format("a ${bar} is a ${foo}", context), "a foo is a bar",
"multiple properties replaced correctly");
}
function test_06_Number_limitSigDigs(t) {
t.plan(9);