Deprecating all prototype extensions. This puts all OpenLayers functionality in the OpenLayers namespace. If you are using any of the Function, String, or Number prototype extensions, start using the functional equivalents in the OpenLayers namespace - the prototype extensions will be gone in 3.0 (closes #712).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4302 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
var g = new OpenLayers.Geometry.Surface();
|
||||
|
||||
t.eq(g.CLASS_NAME, "OpenLayers.Geometry.Surface", "correct CLASS_NAME")
|
||||
t.ok(g.id.startsWith("OpenLayers.Geometry.Surface_"), "id correctly set");
|
||||
t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry.Surface_"),
|
||||
"id correctly set");
|
||||
}
|
||||
|
||||
|
||||
|
||||
+42
-36
@@ -11,9 +11,12 @@
|
||||
var test1 = "chicken";
|
||||
var test2 = "beet";
|
||||
|
||||
t.ok(str.startsWith("chicken"), " 'chickenHead' starts with 'chicken'");
|
||||
t.ok(!str.startsWith("Head"), " 'chickenHead' contains 'Head' but does *not* start with it");
|
||||
t.ok(!str.startsWith("beet"), "'chickenHead' doesnt start with 'beet'");
|
||||
t.ok(OpenLayers.String.startsWith(str, "chicken"),
|
||||
"'chickenHead' starts with 'chicken'");
|
||||
t.ok(!OpenLayers.String.startsWith(str, "Head"),
|
||||
"'chickenHead' does not start with 'Head'");
|
||||
t.ok(!OpenLayers.String.startsWith(str, "beet"),
|
||||
"'chickenHead' doesnt start with 'beet'");
|
||||
}
|
||||
|
||||
function test_02_String_contains(t) {
|
||||
@@ -21,81 +24,84 @@
|
||||
|
||||
var str = "chickenHead";
|
||||
|
||||
t.ok(str.contains("chicken"), "(beginning) 'chickenHead' contains with 'chicken'");
|
||||
t.ok(str.contains("ick"), "(middle) 'chickenHead' contains with 'ick'");
|
||||
t.ok(str.contains("Head"), "(end) 'chickenHead' contains with 'Head'");
|
||||
t.ok(!str.startsWith("beet"), "'chickenHead' doesnt start with 'beet'");
|
||||
t.ok(OpenLayers.String.contains(str, "chicken"),
|
||||
"(beginning) 'chickenHead' contains with 'chicken'");
|
||||
t.ok(OpenLayers.String.contains(str, "ick"),
|
||||
"(middle) 'chickenHead' contains with 'ick'");
|
||||
t.ok(OpenLayers.String.contains(str, "Head"),
|
||||
"(end) 'chickenHead' contains with 'Head'");
|
||||
t.ok(!OpenLayers.String.startsWith(str, "beet"),
|
||||
"'chickenHead' doesnt start with 'beet'");
|
||||
}
|
||||
|
||||
function test_03_String_trim(t) {
|
||||
t.plan(5);
|
||||
|
||||
var str = "chickenHead";
|
||||
t.eq(str.trim(), "chickenHead", "string with no extra whitespace is left alone");
|
||||
t.eq(OpenLayers.String.trim(str),
|
||||
"chickenHead", "string with no extra whitespace is left alone");
|
||||
|
||||
str = " chickenHead";
|
||||
t.eq(str.trim(), "chickenHead", "string with extra whitespace at beginning is trimmed correctly");
|
||||
t.eq(OpenLayers.String.trim(str),
|
||||
"chickenHead", "string with extra whitespace at beginning is trimmed correctly");
|
||||
|
||||
str = "chickenHead ";
|
||||
t.eq(str.trim(), "chickenHead", "string with extra whitespace at end is trimmed correctly");
|
||||
t.eq(OpenLayers.String.trim(str),
|
||||
"chickenHead", "string with extra whitespace at end is trimmed correctly");
|
||||
|
||||
str = " chickenHead ";
|
||||
t.eq(str.trim(), "chickenHead", "string with extra whitespace at beginning and end is trimmed correctly");
|
||||
t.eq(OpenLayers.String.trim(str),
|
||||
"chickenHead", "string with extra whitespace at beginning and end is trimmed correctly");
|
||||
|
||||
str = " ";
|
||||
t.eq(str.trim(), "", "whitespace string is trimmed correctly");
|
||||
t.eq(OpenLayers.String.trim(str), "", "whitespace string is trimmed correctly");
|
||||
}
|
||||
|
||||
function test_05_String_camelize(t) {
|
||||
t.plan(7);
|
||||
|
||||
var str = "chickenhead";
|
||||
t.eq(str.camelize(), "chickenhead", "string with no hyphens is left alone");
|
||||
t.eq(OpenLayers.String.camelize(str), "chickenhead", "string with no hyphens is left alone");
|
||||
|
||||
str = "chicken-head";
|
||||
t.eq(str.camelize(), "chickenHead", "string with one middle hyphen is camelized correctly");
|
||||
t.eq(OpenLayers.String.camelize(str), "chickenHead", "string with one middle hyphen is camelized correctly");
|
||||
|
||||
str = "chicken-head-man";
|
||||
t.eq(str.camelize(), "chickenHeadMan", "string with multiple middle hyphens is camelized correctly");
|
||||
t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens is camelized correctly");
|
||||
|
||||
str = "-chickenhead";
|
||||
t.eq(str.camelize(), "Chickenhead", "string with starting hyphen is camelized correctly (capitalized)");
|
||||
t.eq(OpenLayers.String.camelize(str), "Chickenhead", "string with starting hyphen is camelized correctly (capitalized)");
|
||||
|
||||
str = "-chicken-head-man";
|
||||
t.eq(str.camelize(), "ChickenHeadMan", "string with starting hypen and multiple middle hyphens is camelized correctly");
|
||||
t.eq(OpenLayers.String.camelize(str), "ChickenHeadMan", "string with starting hypen and multiple middle hyphens is camelized correctly");
|
||||
|
||||
str = "chicken-";
|
||||
t.eq(str.camelize(), "chicken", "string ending in hyphen is camelized correctly (hyphen dropped)");
|
||||
t.eq(OpenLayers.String.camelize(str), "chicken", "string ending in hyphen is camelized correctly (hyphen dropped)");
|
||||
|
||||
str = "chicken-head-man-";
|
||||
t.eq(str.camelize(), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)");
|
||||
t.eq(OpenLayers.String.camelize(str), "chickenHeadMan", "string with multiple middle hyphens and end hyphen is camelized correctly (end hyphen dropped)");
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_06_Number_limitSigDigs(t) {
|
||||
t.plan(10);
|
||||
t.plan(9);
|
||||
|
||||
var num = 123456789;
|
||||
t.eq(num.limitSigDigs(), 0, "passing 'null' as sig returns 0");
|
||||
t.eq(num.limitSigDigs(-1), 0, "passing -1 as sig returns 0");
|
||||
t.eq(num.limitSigDigs(0), 0, "passing 0 as sig returns 0");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num), 0, "passing 'null' as sig returns 0");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, -1), 0, "passing -1 as sig returns 0");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 0), 0, "passing 0 as sig returns 0");
|
||||
|
||||
t.eq(num.limitSigDigs(15), 123456789, "passing sig greater than num digits in number returns number unmodified");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 15), 123456789, "passing sig greater than num digits in number returns number unmodified");
|
||||
|
||||
t.eq(num.limitSigDigs(1), 100000000, "passing sig 1 works");
|
||||
t.eq(num.limitSigDigs(3), 123000000, "passing middle sig works (rounds down)");
|
||||
t.eq(num.limitSigDigs(5), 123460000, "passing middle sig works (rounds up)");
|
||||
t.eq(num.limitSigDigs(9), 123456789, "passing sig equal to num digits in number works");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 1), 100000000, "passing sig 1 works");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 3), 123000000, "passing middle sig works (rounds down)");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 5), 123460000, "passing middle sig works (rounds up)");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 9), 123456789, "passing sig equal to num digits in number works");
|
||||
|
||||
var temp = OpenLayers.Console.error;
|
||||
OpenLayers.Console.error = function() {
|
||||
t.ok(true, "error reported when run on floating point number")
|
||||
}
|
||||
num = 1234.56789;
|
||||
t.ok(num.limitSigDigs(5) == null, "running limSigDig() on a floating point number returns null");
|
||||
t.eq(OpenLayers.Number.limitSigDigs(num, 5), 1234.6, "running limSigDig() on a floating point number works fine");
|
||||
|
||||
OpenLayers.Console.error = temp;
|
||||
}
|
||||
|
||||
function test_07_Function_bind(t) {
|
||||
@@ -115,7 +121,7 @@
|
||||
t.eq(arguments.length, 4, "correct number of arguments ((regression test for #876))");
|
||||
};
|
||||
|
||||
var newFoo = foo.bind(g_obj, g_Arg1, g_Arg2);
|
||||
var newFoo = OpenLayers.Function.bind(foo, g_obj, g_Arg1, g_Arg2);
|
||||
|
||||
newFoo(g_Arg3, g_Arg4);
|
||||
|
||||
@@ -135,7 +141,7 @@
|
||||
g_X = x;
|
||||
};
|
||||
|
||||
var newFoo = foo.bindAsEventListener(g_obj);
|
||||
var newFoo = OpenLayers.Function.bindAsEventListener(foo, g_obj);
|
||||
|
||||
|
||||
g_X = null;
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
|
||||
t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" );
|
||||
t.eq( feature.layer, layer, "feature.layer set correctly" );
|
||||
t.ok( feature.id.startsWith("OpenLayers.Feature_"), "feature.id set correctly" );
|
||||
t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"),
|
||||
"feature.id set correctly");
|
||||
t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" );
|
||||
t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" );
|
||||
t.ok( feature.data.iconSize.equals(iconSize), "feature.data.iconSize set correctly" );
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
var g = new OpenLayers.Geometry();
|
||||
|
||||
t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME")
|
||||
t.ok(g.id.startsWith("OpenLayers.Geometry_"), "id correctly set");
|
||||
t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"),
|
||||
"id correctly set");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +21,8 @@
|
||||
var clone = geometry.clone();
|
||||
|
||||
t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME")
|
||||
t.ok(clone.id.startsWith("OpenLayers.Geometry_"), "id correctly set");
|
||||
t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"),
|
||||
"id correctly set");
|
||||
}
|
||||
|
||||
function test_02_Geometry_setBounds(t) {
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
popup = new OpenLayers.Popup();
|
||||
|
||||
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
|
||||
t.ok(popup.id.startsWith("OpenLayers.Popup"), "valid default popupid");
|
||||
t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"),
|
||||
"valid default popupid");
|
||||
var firstID = popup.id;
|
||||
t.ok(popup.size.equals(size), "good default popup.size");
|
||||
t.eq(popup.contentHTML, "", "good default popup.contentHTML");
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
t.ok( tile.size.equals(size), "tile.size is set correctly" );
|
||||
|
||||
t.ok( tile.id != null, "tile is given an id");
|
||||
t.ok( tile.id.startsWith("Tile_"), "tile's id starts correctly");
|
||||
t.ok(OpenLayers.String.startsWith(tile.id, "Tile_"),
|
||||
"tile's id starts correctly");
|
||||
t.ok( tile.events != null, "tile's events intitialized");
|
||||
}
|
||||
|
||||
|
||||
+5
-44
@@ -11,25 +11,6 @@
|
||||
"getImagesLocation()" );
|
||||
}
|
||||
|
||||
function test_02_Util_Strings(t) {
|
||||
t.plan(5);
|
||||
|
||||
var str = " chicken pox ";
|
||||
|
||||
t.ok(str.contains("chicken"), "contains() function correctly finds an embedded string");
|
||||
t.ok(!str.contains("marsupial"), "contains() function correctly does not finds an random string");
|
||||
|
||||
|
||||
var trimmedStr = str.trim();
|
||||
|
||||
t.eq(trimmedStr, "chicken pox", "String.trim works correctly");
|
||||
|
||||
t.eq(trimmedStr.startsWith("chicken"), true, "String.startsWith correctly finds chicken");
|
||||
t.eq(trimmedStr.startsWith("dolphin"), false, "String.startsWith correctly does not find turkey");
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_03_Util_Array(t) {
|
||||
t.plan( 1 );
|
||||
|
||||
@@ -423,34 +404,14 @@
|
||||
t.plan(2);
|
||||
|
||||
var id = OpenLayers.Util.createUniqueID();
|
||||
t.ok( id.startsWith("id_"), "default OpenLayers.Util.createUniqueID starts id correctly");
|
||||
t.ok(OpenLayers.String.startsWith(id, "id_"),
|
||||
"default OpenLayers.Util.createUniqueID starts id correctly");
|
||||
|
||||
var id = OpenLayers.Util.createUniqueID("chicken");
|
||||
t.ok( id.startsWith("chicken"), "OpenLayers.Util.createUniqueID starts id correctly");
|
||||
t.ok(OpenLayers.String.startsWith(id, "chicken"),
|
||||
"OpenLayers.Util.createUniqueID starts id correctly");
|
||||
}
|
||||
|
||||
function test_12_Util_limitSigDigs(t) {
|
||||
t.plan(7);
|
||||
|
||||
var x;
|
||||
|
||||
x = 123456;
|
||||
t.eq(x.limitSigDigs(3), 123000, "correctly rounds down");
|
||||
|
||||
x = 555555;
|
||||
t.eq(x.limitSigDigs(3), 556000, "correctly rounds up");
|
||||
|
||||
x = 66;
|
||||
t.eq(x.limitSigDigs(3), 66, "correctly handles number smaller than sigdig");
|
||||
|
||||
t.eq(x.limitSigDigs(null), 0, "correctly handles null sigdig");
|
||||
t.eq(x.limitSigDigs(0), 0, "correctly handles 0 sigdig");
|
||||
t.eq(x.limitSigDigs(-1), 0, "correctly handles negative sigdig");
|
||||
|
||||
x = 0;
|
||||
t.eq(x.limitSigDigs(2), 0, "correctly handles 0 number");
|
||||
}
|
||||
|
||||
|
||||
function test_13_Util_normalizeScale(t) {
|
||||
t.plan(2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user