Merge pull request #626 from mpriour/zeropad

Consolidate numeric zero padding functions (r=@bartvde)
This commit is contained in:
Bart van den Eijnden
2013-01-09 00:26:17 -08:00
6 changed files with 54 additions and 63 deletions

View File

@@ -278,6 +278,17 @@
OpenLayers.Number.decimalSeparator = ",";
t.eq(format(num, 3), "12.345,679", "changing thousands/decimal separator globally works");
}
function test_Number_zeroPad(t) {
t.plan(6);
var pad = OpenLayers.Number.zeroPad;
t.eq(pad(15, 4), "0015", "left padding works");
t.eq(pad(15, 2), "15", "no left padding when equal to number of digits");
t.eq(pad(15, 1), "15", "no left padding when less than number of digits");
t.eq(pad(10, 5, 2), "01010", "radix modified and padding works");
t.eq(pad(10, 5, 8), "00012", "radix modified and padding works");
t.eq(pad(10, 5, 36), "0000a", "radix modified and padding works");
}
function test_Function_bind(t) {
t.plan(12);

View File

@@ -187,7 +187,9 @@
}
/**
* Check our utility function for generating tile indexes against a file cache
* Check the utility function for generating tile indexes against a file cache
* This is already tested in BaseTypes test, but these are specific,
* common conversions that this class will rely on, so the tests are retained
*/
function test_Layer_ARCGISCACHE_zeroPad(t) {
t.plan(4);
@@ -195,10 +197,10 @@
var layer = new OpenLayers.Layer.ArcGISCache('test', null, { });
//some tile examples
t.ok('00000001' == layer.zeroPad(1, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000020' == layer.zeroPad(32, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000100' == layer.zeroPad(256, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00001000' == layer.zeroPad(4096, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000001' == OpenLayers.Number.zeroPad(1, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000020' == OpenLayers.Number.zeroPad(32, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00000100' == OpenLayers.Number.zeroPad(256, 8, 16), 'zeroPad should generate tile indexes properly ');
t.ok('00001000' == OpenLayers.Number.zeroPad(4096, 8, 16), 'zeroPad should generate tile indexes properly ');
}
/**