Shuffle assertions
This commit is contained in:
36
src/ol/assertionerror.js
Normal file
36
src/ol/assertionerror.js
Normal file
@@ -0,0 +1,36 @@
|
||||
goog.provide('ol.AssertionError');
|
||||
|
||||
goog.require('ol');
|
||||
|
||||
/**
|
||||
* Error object thrown when an assertion failed. This is an ECMA-262 Error,
|
||||
* extended with a `code` property.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
|
||||
* @constructor
|
||||
* @extends {Error}
|
||||
* @implements {oli.AssertionError}
|
||||
* @param {number} code Error code.
|
||||
*/
|
||||
ol.AssertionError = function(code) {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.message = 'Assertion failed. See ' +
|
||||
(ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') +
|
||||
'/doc/errors/#' + code + ' for details.';
|
||||
|
||||
/**
|
||||
* Error code. The meaning of the code can be found on
|
||||
* {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with
|
||||
* the version found in the OpenLayers script's header comment if a version
|
||||
* other than the latest is used).
|
||||
* @type {number}
|
||||
* @api
|
||||
*/
|
||||
this.code = code;
|
||||
|
||||
this.name = 'AssertionError';
|
||||
|
||||
};
|
||||
ol.inherits(ol.AssertionError, Error);
|
||||
15
src/ol/asserts.js
Normal file
15
src/ol/asserts.js
Normal file
@@ -0,0 +1,15 @@
|
||||
goog.provide('ol.asserts');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.AssertionError');
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} assertion Assertion we expected to be truthy.
|
||||
* @param {number} errorCode Error code.
|
||||
*/
|
||||
ol.asserts.assert = function(assertion, errorCode) {
|
||||
if (!assertion) {
|
||||
throw new ol.AssertionError(errorCode);
|
||||
}
|
||||
};
|
||||
@@ -159,7 +159,7 @@ ol.color.fromStringInternal_ = function(s) {
|
||||
|
||||
if (ol.color.hexColorRe_.exec(s)) { // hex
|
||||
var n = s.length - 1; // number of hex digits
|
||||
ol.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits
|
||||
ol.asserts.assert(n == 3 || n == 6, 54); // Hex color should have 3 or 6 digits
|
||||
var d = n == 3 ? 1 : 2; // number of digits per channel
|
||||
r = parseInt(s.substr(1 + 0 * d, d), 16);
|
||||
g = parseInt(s.substr(1 + 1 * d, d), 16);
|
||||
@@ -183,7 +183,7 @@ ol.color.fromStringInternal_ = function(s) {
|
||||
b = Number(match[3]);
|
||||
color = ol.color.normalize([r, g, b, 1]);
|
||||
} else {
|
||||
ol.assert(false, 14); // Invalid color
|
||||
ol.asserts.assert(false, 14); // Invalid color
|
||||
}
|
||||
return /** @type {ol.Color} */ (color);
|
||||
};
|
||||
|
||||
@@ -245,7 +245,7 @@ ol.control.ScaleLine.prototype.updateElement_ = function() {
|
||||
pointResolution /= 1609.3472;
|
||||
}
|
||||
} else {
|
||||
ol.assert(false, 33); // Invalid units
|
||||
ol.asserts.assert(false, 33); // Invalid units
|
||||
}
|
||||
|
||||
var i = 3 * Math.floor(
|
||||
|
||||
@@ -526,7 +526,7 @@ ol.extent.getCorner = function(extent, corner) {
|
||||
} else if (corner === ol.extent.Corner.TOP_RIGHT) {
|
||||
coordinate = ol.extent.getTopRight(extent);
|
||||
} else {
|
||||
ol.assert(false, 13); // Invalid corner
|
||||
ol.asserts.assert(false, 13); // Invalid corner
|
||||
}
|
||||
return /** @type {!ol.Coordinate} */ (coordinate);
|
||||
};
|
||||
|
||||
@@ -301,7 +301,7 @@ ol.Feature.createStyleFunction = function(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
styles = obj;
|
||||
} else {
|
||||
ol.assert(obj instanceof ol.style.Style,
|
||||
ol.asserts.assert(obj instanceof ol.style.Style,
|
||||
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
|
||||
styles = [obj];
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ ol.format.EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
|
||||
y: coordinates[1]
|
||||
});
|
||||
} else {
|
||||
ol.assert(false, 34); // Invalid geometry layout
|
||||
ol.asserts.assert(false, 34); // Invalid geometry layout
|
||||
}
|
||||
return /** @type {EsriJSONGeometry} */ (esriJSON);
|
||||
};
|
||||
|
||||
@@ -422,7 +422,7 @@ ol.format.GeoJSON.prototype.readFeaturesFromObject = function(
|
||||
opt_options));
|
||||
}
|
||||
} else {
|
||||
ol.assert(false, 35); // Unknown GeoJSON object type
|
||||
ol.asserts.assert(false, 35); // Unknown GeoJSON object type
|
||||
}
|
||||
return /** Array.<ol.Feature> */ (features);
|
||||
};
|
||||
@@ -478,7 +478,7 @@ ol.format.GeoJSON.prototype.readProjectionFromObject = function(object) {
|
||||
// is fixed and widely deployed.
|
||||
projection = ol.proj.get('EPSG:' + crs.properties.code);
|
||||
} else {
|
||||
ol.assert(false, 36); // Unknown SRS type
|
||||
ol.asserts.assert(false, 36); // Unknown SRS type
|
||||
}
|
||||
} else {
|
||||
projection = this.defaultDataProjection;
|
||||
|
||||
@@ -981,7 +981,7 @@ ol.format.KML.readMultiGeometry_ = function(node, objectStack) {
|
||||
} else if (type == ol.geom.GeometryType.GEOMETRY_COLLECTION) {
|
||||
multiGeometry = new ol.geom.GeometryCollection(geometries);
|
||||
} else {
|
||||
ol.assert(false, 37); // Unknown geometry type found
|
||||
ol.asserts.assert(false, 37); // Unknown geometry type found
|
||||
}
|
||||
} else {
|
||||
multiGeometry = new ol.geom.GeometryCollection(geometries);
|
||||
@@ -1217,7 +1217,7 @@ ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) {
|
||||
} else if (typeof styleMapValue === 'string') {
|
||||
placemarkObject['styleUrl'] = styleMapValue;
|
||||
} else {
|
||||
ol.assert(false, 38); // `styleMapValue` has an unknown type
|
||||
ol.asserts.assert(false, 38); // `styleMapValue` has an unknown type
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2067,7 +2067,7 @@ ol.format.KML.writeCoordinatesTextNode_ = function(node, coordinates, objectStac
|
||||
layout == ol.geom.GeometryLayout.XYZM) {
|
||||
dimension = 3;
|
||||
} else {
|
||||
ol.assert(false, 34); // Invalid geometry layout
|
||||
ol.asserts.assert(false, 34); // Invalid geometry layout
|
||||
}
|
||||
|
||||
var d, i;
|
||||
@@ -2259,7 +2259,7 @@ ol.format.KML.writeMultiGeometry_ = function(node, geometry, objectStack) {
|
||||
(/** @type {ol.geom.MultiPolygon} */ (geometry)).getPolygons();
|
||||
factory = ol.format.KML.POLYGON_NODE_FACTORY_;
|
||||
} else {
|
||||
ol.assert(false, 39); // Unknown geometry type
|
||||
ol.asserts.assert(false, 39); // Unknown geometry type
|
||||
}
|
||||
ol.xml.pushSerializeAndPop(context,
|
||||
ol.format.KML.MULTI_GEOMETRY_SERIALIZERS_, factory,
|
||||
|
||||
@@ -355,7 +355,7 @@ ol.format.Polyline.prototype.writeFeatureText = function(feature, opt_options) {
|
||||
if (geometry) {
|
||||
return this.writeGeometryText(geometry, opt_options);
|
||||
} else {
|
||||
ol.assert(false, 40); // Expected `feature` to have a geometry
|
||||
ol.asserts.assert(false, 40); // Expected `feature` to have a geometry
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -386,7 +386,7 @@ ol.format.WFS.writeOgcFidFilter_ = function(node, fid, objectStack) {
|
||||
*/
|
||||
ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
ol.assert(feature.getId() !== undefined, 26); // Features must have an id set
|
||||
ol.asserts.assert(feature.getId() !== undefined, 26); // Features must have an id set
|
||||
var featureType = context['featureType'];
|
||||
var featurePrefix = context['featurePrefix'];
|
||||
featurePrefix = featurePrefix ? featurePrefix :
|
||||
@@ -410,7 +410,7 @@ ol.format.WFS.writeDelete_ = function(node, feature, objectStack) {
|
||||
*/
|
||||
ol.format.WFS.writeUpdate_ = function(node, feature, objectStack) {
|
||||
var context = objectStack[objectStack.length - 1];
|
||||
ol.assert(feature.getId() !== undefined, 27); // Features must have an id set
|
||||
ol.asserts.assert(feature.getId() !== undefined, 27); // Features must have an id set
|
||||
var featureType = context['featureType'];
|
||||
var featurePrefix = context['featurePrefix'];
|
||||
featurePrefix = featurePrefix ? featurePrefix :
|
||||
@@ -802,7 +802,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) {
|
||||
}
|
||||
filter = options.filter;
|
||||
if (options.bbox) {
|
||||
ol.assert(options.geometryName,
|
||||
ol.asserts.assert(options.geometryName,
|
||||
12); // `options.geometryName` must also be provided when `options.bbox` is set
|
||||
var bbox = ol.format.ogc.filter.bbox(
|
||||
/** @type {string} */ (options.geometryName), options.bbox, options.srsName);
|
||||
@@ -826,7 +826,7 @@ ol.format.WFS.prototype.writeGetFeature = function(options) {
|
||||
'filter': filter,
|
||||
'propertyNames': options.propertyNames ? options.propertyNames : []
|
||||
};
|
||||
ol.assert(Array.isArray(options.featureTypes),
|
||||
ol.asserts.assert(Array.isArray(options.featureTypes),
|
||||
11); // `options.featureTypes` should be an Array
|
||||
ol.format.WFS.writeGetFeature_(node, /** @type {!Array.<string>} */ (options.featureTypes), [context]);
|
||||
return node;
|
||||
|
||||
@@ -303,48 +303,3 @@ if (typeof window !== 'undefined') {
|
||||
} else if (typeof self !== 'undefined') {
|
||||
ol.global = self;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Error object thrown when an assertion failed. This is an ECMA-262 Error,
|
||||
* extended with a `code` property.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error}
|
||||
* @constructor
|
||||
* @extends {Error}
|
||||
* @implements {oli.AssertionError}
|
||||
* @param {number} code Error code.
|
||||
*/
|
||||
ol.AssertionError = function(code) {
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
this.message = 'Assertion failed. See ' +
|
||||
(ol.VERSION ? 'http://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') +
|
||||
'/doc/errors/#' + code + ' for details.';
|
||||
|
||||
/**
|
||||
* Error code. The meaning of the code can be found on
|
||||
* {@link http://openlayers.org/en/latest/errors.html} (replace `latest` with
|
||||
* the version found in the OpenLayers script's header comment if a version
|
||||
* other than the latest is used).
|
||||
* @type {number}
|
||||
* @api
|
||||
*/
|
||||
this.code = code;
|
||||
|
||||
this.name = 'AssertionError';
|
||||
|
||||
};
|
||||
ol.inherits(ol.AssertionError, Error);
|
||||
|
||||
|
||||
/**
|
||||
* @param {*} assertion Assertion we expected to be truthy.
|
||||
* @param {number} errorCode Error code.
|
||||
*/
|
||||
ol.assert = function(assertion, errorCode) {
|
||||
if (!assertion) {
|
||||
throw new ol.AssertionError(errorCode);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -225,7 +225,7 @@ ol.interaction.Select.prototype.getFeatures = function() {
|
||||
* @api
|
||||
*/
|
||||
ol.interaction.Select.prototype.getLayer = function(feature) {
|
||||
ol.assert(feature instanceof ol.Feature,
|
||||
ol.asserts.assert(feature instanceof ol.Feature,
|
||||
42); // Expected an `ol.Feature`, but got an `ol.RenderFeature`
|
||||
var key = ol.getUid(feature);
|
||||
return /** @type {ol.layer.Vector} */ (this.featureLayerAssociation_[key]);
|
||||
|
||||
@@ -61,7 +61,7 @@ ol.layer.Group = function(opt_options) {
|
||||
if (Array.isArray(layers)) {
|
||||
layers = new ol.Collection(layers.slice());
|
||||
} else {
|
||||
ol.assert(layers instanceof ol.Collection,
|
||||
ol.asserts.assert(layers instanceof ol.Collection,
|
||||
43); // Expected `layers` to be an array or an `ol.Collection`
|
||||
layers = layers;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ ol.layer.VectorTile = function(opt_options) {
|
||||
this.setUseInterimTilesOnError(options.useInterimTilesOnError ?
|
||||
options.useInterimTilesOnError : true);
|
||||
|
||||
ol.assert(options.renderMode == undefined ||
|
||||
ol.asserts.assert(options.renderMode == undefined ||
|
||||
options.renderMode == ol.layer.VectorTileRenderType.IMAGE ||
|
||||
options.renderMode == ol.layer.VectorTileRenderType.HYBRID ||
|
||||
options.renderMode == ol.layer.VectorTileRenderType.VECTOR,
|
||||
|
||||
@@ -1443,8 +1443,8 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
} else if (logo instanceof HTMLElement) {
|
||||
logos[ol.getUid(logo).toString()] = logo;
|
||||
} else if (logo) {
|
||||
ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
|
||||
ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
|
||||
ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
|
||||
ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
|
||||
logos[logo.src] = logo.href;
|
||||
}
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
} else if (typeof options.renderer === 'string') {
|
||||
rendererTypes = [options.renderer];
|
||||
} else {
|
||||
ol.assert(false, 46); // Incorrect format for `renderer` option
|
||||
ol.asserts.assert(false, 46); // Incorrect format for `renderer` option
|
||||
}
|
||||
} else {
|
||||
rendererTypes = ol.DEFAULT_RENDERER_TYPES;
|
||||
@@ -1506,7 +1506,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.controls)) {
|
||||
controls = new ol.Collection(options.controls.slice());
|
||||
} else {
|
||||
ol.assert(options.controls instanceof ol.Collection,
|
||||
ol.asserts.assert(options.controls instanceof ol.Collection,
|
||||
47); // Expected `controls` to be an array or an `ol.Collection`
|
||||
controls = options.controls;
|
||||
}
|
||||
@@ -1519,7 +1519,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.interactions)) {
|
||||
interactions = new ol.Collection(options.interactions.slice());
|
||||
} else {
|
||||
ol.assert(options.interactions instanceof ol.Collection,
|
||||
ol.asserts.assert(options.interactions instanceof ol.Collection,
|
||||
48); // Expected `interactions` to be an array or an `ol.Collection`
|
||||
interactions = options.interactions;
|
||||
}
|
||||
@@ -1532,7 +1532,7 @@ ol.Map.createOptionsInternal = function(options) {
|
||||
if (Array.isArray(options.overlays)) {
|
||||
overlays = new ol.Collection(options.overlays.slice());
|
||||
} else {
|
||||
ol.assert(options.overlays instanceof ol.Collection,
|
||||
ol.asserts.assert(options.overlays instanceof ol.Collection,
|
||||
49); // Expected `overlays` to be an array or an `ol.Collection`
|
||||
overlays = options.overlays;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ ol.math.cosh = (function() {
|
||||
* @return {number} The smallest power of two greater than or equal to x.
|
||||
*/
|
||||
ol.math.roundUpToPowerOfTwo = function(x) {
|
||||
ol.assert(0 < x, 29); // `x` must be greater than `0`
|
||||
ol.asserts.assert(0 < x, 29); // `x` must be greater than `0`
|
||||
return Math.pow(2, Math.ceil(Math.log(x) / Math.LN2));
|
||||
};
|
||||
|
||||
|
||||
@@ -221,8 +221,8 @@ ol.renderer.Layer.prototype.updateLogos = function(frameState, source) {
|
||||
if (typeof logo === 'string') {
|
||||
frameState.logos[logo] = '';
|
||||
} else if (logo) {
|
||||
ol.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
|
||||
ol.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
|
||||
ol.asserts.assert(typeof logo.href == 'string', 44); // `logo.href` should be a string.
|
||||
ol.asserts.assert(typeof logo.src == 'string', 45); // `logo.src` should be a string.
|
||||
frameState.logos[logo.src] = logo.href;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ ol.source.Cluster = function(options) {
|
||||
*/
|
||||
this.geometryFunction_ = options.geometryFunction || function(feature) {
|
||||
var geometry = /** @type {ol.geom.Point} */ (feature.getGeometry());
|
||||
ol.assert(geometry instanceof ol.geom.Point,
|
||||
ol.asserts.assert(geometry instanceof ol.geom.Point,
|
||||
10); // The default `geometryFunction` can only handle `ol.geom.Point` geometries
|
||||
return geometry;
|
||||
};
|
||||
|
||||
@@ -211,7 +211,7 @@ ol.source.ImageArcGISRest.prototype.getRequestUrl_ = function(extent, size, pixe
|
||||
.replace(/MapServer\/?$/, 'MapServer/export')
|
||||
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
|
||||
if (modifiedUrl == url) {
|
||||
ol.assert(false, 50); // `options.featureTypes` should be an Array
|
||||
ol.asserts.assert(false, 50); // `options.featureTypes` should be an Array
|
||||
}
|
||||
return ol.uri.appendParams(modifiedUrl, params);
|
||||
};
|
||||
|
||||
@@ -267,7 +267,7 @@ ol.source.ImageWMS.prototype.getImageLoadFunction = function() {
|
||||
*/
|
||||
ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio, projection, params) {
|
||||
|
||||
ol.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()`
|
||||
ol.asserts.assert(this.url_ !== undefined, 9); // `url` must be configured or set using `#setUrl()`
|
||||
|
||||
params[this.v13_ ? 'CRS' : 'SRS'] = projection.getCode();
|
||||
|
||||
@@ -293,7 +293,7 @@ ol.source.ImageWMS.prototype.getRequestUrl_ = function(extent, size, pixelRatio,
|
||||
params['DPI'] = 90 * pixelRatio;
|
||||
break;
|
||||
default:
|
||||
ol.assert(false, 8); // Unknown `serverType` configured
|
||||
ol.asserts.assert(false, 8); // Unknown `serverType` configured
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ ol.source.TileArcGISRest.prototype.getRequestUrl_ = function(tileCoord, tileSize
|
||||
.replace(/MapServer\/?$/, 'MapServer/export')
|
||||
.replace(/ImageServer\/?$/, 'ImageServer/exportImage');
|
||||
if (modifiedUrl == url) {
|
||||
ol.assert(false, 50); // Cannot determine Rest Service from url
|
||||
ol.asserts.assert(false, 50); // Cannot determine Rest Service from url
|
||||
}
|
||||
return ol.uri.appendParams(modifiedUrl, params);
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@ ol.source.TileUTFGrid = function(options) {
|
||||
} else if (options.tileJSON) {
|
||||
this.handleTileJSONResponse(options.tileJSON);
|
||||
} else {
|
||||
ol.assert(false, 51); // Either `url` or `tileJSON` options must be provided
|
||||
ol.asserts.assert(false, 51); // Either `url` or `tileJSON` options must be provided
|
||||
}
|
||||
};
|
||||
ol.inherits(ol.source.TileUTFGrid, ol.source.Tile);
|
||||
|
||||
@@ -237,7 +237,7 @@ ol.source.TileWMS.prototype.getRequestUrl_ = function(tileCoord, tileSize, tileE
|
||||
params['DPI'] = 90 * pixelRatio;
|
||||
break;
|
||||
default:
|
||||
ol.assert(false, 52); // Unknown `serverType` configured
|
||||
ol.asserts.assert(false, 52); // Unknown `serverType` configured
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ ol.source.Vector = function(opt_options) {
|
||||
if (options.loader !== undefined) {
|
||||
this.loader_ = options.loader;
|
||||
} else if (this.url_ !== undefined) {
|
||||
ol.assert(this.format_, 7); // `format` must be set when `url` is set
|
||||
ol.asserts.assert(this.format_, 7); // `format` must be set when `url` is set
|
||||
// create a XHR feature loader for "url" and "format"
|
||||
this.loader_ = ol.featureloader.xhr(this.url_, /** @type {ol.format.Feature} */ (this.format_));
|
||||
}
|
||||
@@ -257,7 +257,7 @@ ol.source.Vector.prototype.addToIndex_ = function(featureKey, feature) {
|
||||
valid = false;
|
||||
}
|
||||
} else {
|
||||
ol.assert(!(featureKey in this.undefIdIndex_),
|
||||
ol.asserts.assert(!(featureKey in this.undefIdIndex_),
|
||||
30); // The passed `feature` was already added to the source
|
||||
this.undefIdIndex_[featureKey] = feature;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ ol.source.Zoomify = function(opt_options) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ol.assert(false, 53); // Unknown `tierSizeCalculation` configured
|
||||
ol.asserts.assert(false, 53); // Unknown `tierSizeCalculation` configured
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ ol.structs.LRUCache.prototype.forEach = function(f, opt_this) {
|
||||
*/
|
||||
ol.structs.LRUCache.prototype.get = function(key) {
|
||||
var entry = this.entries_[key];
|
||||
ol.assert(entry !== undefined,
|
||||
ol.asserts.assert(entry !== undefined,
|
||||
15); // Tried to get a value for a key that does not exist in the cache
|
||||
if (entry === this.newest_) {
|
||||
return entry.value_;
|
||||
@@ -244,7 +244,7 @@ ol.structs.LRUCache.prototype.replace = function(key, value) {
|
||||
ol.structs.LRUCache.prototype.set = function(key, value) {
|
||||
goog.DEBUG && console.assert(!(key in {}),
|
||||
'key is not a standard property of objects (e.g. "__proto__")');
|
||||
ol.assert(!(key in this.entries_),
|
||||
ol.asserts.assert(!(key in this.entries_),
|
||||
16); // Tried to set a value for a key that is used already
|
||||
var entry = /** @type {ol.LRUCacheEntry} */ ({
|
||||
key_: key,
|
||||
|
||||
@@ -125,7 +125,7 @@ ol.structs.PriorityQueue.prototype.dequeue = function() {
|
||||
* @return {boolean} The element was added to the queue.
|
||||
*/
|
||||
ol.structs.PriorityQueue.prototype.enqueue = function(element) {
|
||||
ol.assert(!(this.keyFunction_(element) in this.queuedElements_),
|
||||
ol.asserts.assert(!(this.keyFunction_(element) in this.queuedElements_),
|
||||
31); // Tried to enqueue an `element` that was already added to the queue
|
||||
var priority = this.priorityFunction_(element);
|
||||
if (priority != ol.structs.PriorityQueue.DROP) {
|
||||
|
||||
@@ -101,15 +101,15 @@ ol.style.Icon = function(opt_options) {
|
||||
*/
|
||||
var src = options.src;
|
||||
|
||||
ol.assert(!(src !== undefined && image),
|
||||
ol.asserts.assert(!(src !== undefined && image),
|
||||
4); // `image` and `src` cannot be provided at the same time
|
||||
ol.assert(!image || (image && imgSize),
|
||||
ol.asserts.assert(!image || (image && imgSize),
|
||||
5); // `imgSize` must be set when `image` is provided
|
||||
|
||||
if ((src === undefined || src.length === 0) && image) {
|
||||
src = image.src || ol.getUid(image).toString();
|
||||
}
|
||||
ol.assert(src !== undefined && src.length > 0,
|
||||
ol.asserts.assert(src !== undefined && src.length > 0,
|
||||
6); // A defined and non-empty `src` or `image` must be provided
|
||||
|
||||
/**
|
||||
|
||||
@@ -201,7 +201,7 @@ ol.style.createStyleFunction = function(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
styles = obj;
|
||||
} else {
|
||||
ol.assert(obj instanceof ol.style.Style,
|
||||
ol.asserts.assert(obj instanceof ol.style.Style,
|
||||
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
|
||||
styles = [obj];
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
* @type {!Array.<number>}
|
||||
*/
|
||||
this.resolutions_ = options.resolutions;
|
||||
ol.assert(ol.array.isSorted(this.resolutions_, function(a, b) {
|
||||
ol.asserts.assert(ol.array.isSorted(this.resolutions_, function(a, b) {
|
||||
return b - a;
|
||||
}, true), 17); // `resolutions` must be sorted in descending order
|
||||
|
||||
@@ -55,7 +55,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
this.origins_ = null;
|
||||
if (options.origins !== undefined) {
|
||||
this.origins_ = options.origins;
|
||||
ol.assert(this.origins_.length == this.resolutions_.length,
|
||||
ol.asserts.assert(this.origins_.length == this.resolutions_.length,
|
||||
20); // Number of `origins` and `resolutions` must be equal
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
this.origin_ = ol.extent.getTopLeft(extent);
|
||||
}
|
||||
|
||||
ol.assert(
|
||||
ol.asserts.assert(
|
||||
(!this.origin_ && this.origins_) || (this.origin_ && !this.origins_),
|
||||
18); // Either `origin` or `origins` must be configured, never both
|
||||
|
||||
@@ -77,7 +77,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
this.tileSizes_ = null;
|
||||
if (options.tileSizes !== undefined) {
|
||||
this.tileSizes_ = options.tileSizes;
|
||||
ol.assert(this.tileSizes_.length == this.resolutions_.length,
|
||||
ol.asserts.assert(this.tileSizes_.length == this.resolutions_.length,
|
||||
19); // Number of `tileSizes` and `resolutions` must be equal
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
this.tileSize_ = options.tileSize !== undefined ?
|
||||
options.tileSize :
|
||||
!this.tileSizes_ ? ol.DEFAULT_TILE_SIZE : null;
|
||||
ol.assert(
|
||||
ol.asserts.assert(
|
||||
(!this.tileSize_ && this.tileSizes_) ||
|
||||
(this.tileSize_ && !this.tileSizes_),
|
||||
22); // Either `tileSize` or `tileSizes` must be configured, never both
|
||||
@@ -122,7 +122,7 @@ ol.tilegrid.TileGrid = function(options) {
|
||||
Math.min(0, size[0]), Math.max(size[0] - 1, -1),
|
||||
Math.min(0, size[1]), Math.max(size[1] - 1, -1));
|
||||
if (this.minZoom <= z && z <= this.maxZoom && extent !== undefined) {
|
||||
ol.assert(tileRange.containsTileRange(
|
||||
ol.asserts.assert(tileRange.containsTileRange(
|
||||
this.getTileRangeForExtentAndZ(extent, z)),
|
||||
21); // Tile range for `extent` must not exceed tilegrid width and height
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ ol.TileRange.boundingTileRange = function(var_args) {
|
||||
tileCoordZ = tileCoord[0];
|
||||
tileCoordX = tileCoord[1];
|
||||
tileCoordY = tileCoord[2];
|
||||
ol.assert(tileCoordZ == tileCoord0Z,
|
||||
ol.asserts.assert(tileCoordZ == tileCoord0Z,
|
||||
23); // The passed `ol.TileCoord`s must all have the same `z` value
|
||||
tileRange.minX = Math.min(tileRange.minX, tileCoordX);
|
||||
tileRange.maxX = Math.max(tileRange.maxX, tileCoordX);
|
||||
|
||||
@@ -34,7 +34,7 @@ ol.TileUrlFunction.createFromTemplate = function(template, tileGrid) {
|
||||
.replace(dashYRegEx, function() {
|
||||
var z = tileCoord[0];
|
||||
var range = tileGrid.getFullTileRange(z);
|
||||
ol.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
|
||||
ol.asserts.assert(range, 55); // The {-y} placeholder requires a tile grid with extent
|
||||
var y = range.getHeight() + tileCoord[2];
|
||||
return y.toString();
|
||||
});
|
||||
|
||||
@@ -199,7 +199,7 @@ ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) {
|
||||
*/
|
||||
ol.transform.invert = function(transform) {
|
||||
var det = ol.transform.determinant(transform);
|
||||
ol.assert(det !== 0, 32); // Transformation matrix cannot be inverted
|
||||
ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted
|
||||
|
||||
var a = transform[0];
|
||||
var b = transform[1];
|
||||
|
||||
@@ -289,11 +289,11 @@ ol.View.prototype.getHints = function(opt_hints) {
|
||||
*/
|
||||
ol.View.prototype.calculateExtent = function(size) {
|
||||
var center = /** @type {!ol.Coordinate} */ (this.getCenter());
|
||||
ol.assert(center, 1); // The view center is not defined
|
||||
ol.asserts.assert(center, 1); // The view center is not defined
|
||||
var resolution = /** @type {!number} */ (this.getResolution());
|
||||
ol.assert(resolution !== undefined, 2); // The view resolution is not defined
|
||||
ol.asserts.assert(resolution !== undefined, 2); // The view resolution is not defined
|
||||
var rotation = /** @type {!number} */ (this.getRotation());
|
||||
ol.assert(rotation !== undefined, 3); // The view rotation is not defined
|
||||
ol.asserts.assert(rotation !== undefined, 3); // The view rotation is not defined
|
||||
|
||||
return ol.extent.getForViewAndSize(center, resolution, rotation, size);
|
||||
};
|
||||
@@ -492,9 +492,9 @@ ol.View.prototype.getZoom = function() {
|
||||
*/
|
||||
ol.View.prototype.fit = function(geometry, size, opt_options) {
|
||||
if (!(geometry instanceof ol.geom.SimpleGeometry)) {
|
||||
ol.assert(Array.isArray(geometry),
|
||||
ol.asserts.assert(Array.isArray(geometry),
|
||||
24); // Invalid extent or geometry provided as `geometry`
|
||||
ol.assert(!ol.extent.isEmpty(geometry),
|
||||
ol.asserts.assert(!ol.extent.isEmpty(geometry),
|
||||
25); // Cannot fit empty extent provided as `geometry`
|
||||
geometry = ol.geom.Polygon.fromExtent(geometry);
|
||||
}
|
||||
|
||||
26
test/spec/ol/assertionerror.test.js
Normal file
26
test/spec/ol/assertionerror.test.js
Normal file
@@ -0,0 +1,26 @@
|
||||
goog.provide('ol.AssertionError.test');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.AssertionError');
|
||||
|
||||
describe('ol.AssertionError', function() {
|
||||
it('generates a message', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.');
|
||||
});
|
||||
it('generates a message with a versioned url', function() {
|
||||
var origVersion = ol.VERSION;
|
||||
ol.VERSION = 'foo';
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.');
|
||||
ol.VERSION = origVersion;
|
||||
});
|
||||
it('has an error code', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.code).to.be(42);
|
||||
});
|
||||
it('has a name', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.name).to.be('AssertionError');
|
||||
});
|
||||
});
|
||||
16
test/spec/ol/asserts.test.js
Normal file
16
test/spec/ol/asserts.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
goog.provide('ol.asserts.asserts.test');
|
||||
|
||||
goog.require('ol.asserts');
|
||||
|
||||
|
||||
describe('ol.asserts', function() {
|
||||
|
||||
describe('ol.asserts.assert', function() {
|
||||
it('throws an exception', function() {
|
||||
expect(function() {
|
||||
ol.asserts.assert(false, 42);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,38 +0,0 @@
|
||||
goog.provide('ol.test');
|
||||
|
||||
goog.require('ol');
|
||||
|
||||
|
||||
describe('ol', function() {
|
||||
|
||||
describe('ol.assert', function() {
|
||||
it('throws an exception', function() {
|
||||
expect(function() {
|
||||
ol.assert(false, 42);
|
||||
}).to.throwException();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.AssertionError', function() {
|
||||
it('generates a message', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.');
|
||||
});
|
||||
it('generates a message with a versioned url', function() {
|
||||
var origVersion = ol.VERSION;
|
||||
ol.VERSION = 'foo';
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.message).to.be('Assertion failed. See http://openlayers.org/en/foo/doc/errors/#42 for details.');
|
||||
ol.VERSION = origVersion;
|
||||
});
|
||||
it('has an error code', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.code).to.be(42);
|
||||
});
|
||||
it('has a name', function() {
|
||||
var error = new ol.AssertionError(42);
|
||||
expect(error.name).to.be('AssertionError');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
goog.provide('ol.test.View');
|
||||
|
||||
goog.require('ol');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.extent');
|
||||
goog.require('ol.geom.LineString');
|
||||
|
||||
Reference in New Issue
Block a user