From b2c71ed269ac46181a580c295857bb92f0ecf496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 3 Nov 2012 00:41:13 +0100 Subject: [PATCH] Add tests showing more usages of createFromTemplate --- test/spec/ol/tileurlfunction.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/spec/ol/tileurlfunction.test.js b/test/spec/ol/tileurlfunction.test.js index 445c2e4daa..d67180e99f 100644 --- a/test/spec/ol/tileurlfunction.test.js +++ b/test/spec/ol/tileurlfunction.test.js @@ -6,6 +6,32 @@ describe('ol.TileUrlFunction', function() { expect(tileUrl(new ol.TileCoord(3, 2, 1))).toEqual('3/2/1'); expect(tileUrl(null)).toBeUndefined(); }); + describe('with number range', function() { + it('creates expected URL', function() { + var template = 'http://tile-{1-3}/{z}/{x}/{y}'; + var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(template); + var tileCoord = new ol.TileCoord(3, 2, 1); + tileCoord.hash = function() { return 3; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-1/3/2/1'); + tileCoord.hash = function() { return 2; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-3/3/2/1'); + tileCoord.hash = function() { return 1; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-2/3/2/1'); + }); + }); + describe('with character range', function() { + it('creates expected URL', function() { + var template = 'http://tile-{c-e}/{z}/{x}/{y}'; + var tileUrlFunction = ol.TileUrlFunction.createFromTemplate(template); + var tileCoord = new ol.TileCoord(3, 2, 1); + tileCoord.hash = function() { return 3; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-c/3/2/1'); + tileCoord.hash = function() { return 2; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-e/3/2/1'); + tileCoord.hash = function() { return 1; }; + expect(tileUrlFunction(tileCoord)).toEqual('http://tile-d/3/2/1'); + }); + }); }); describe('withTileCoordTransform', function() {