Using ol.expression.parse
This commit is contained in:
@@ -1,78 +0,0 @@
|
||||
goog.provide('ol.test.Expression');
|
||||
|
||||
describe('ol.Expression', function() {
|
||||
|
||||
describe('constructor', function() {
|
||||
it('creates an expression', function() {
|
||||
var exp = new ol.Expression('foo');
|
||||
expect(exp).to.be.a(ol.Expression);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
|
||||
it('evaluates and returns the result', function() {
|
||||
// test cases here with unique values only (lack of messages in expect)
|
||||
var cases = [{
|
||||
source: '42', result: 42
|
||||
}, {
|
||||
source: '10 + 10', result: 20
|
||||
}, {
|
||||
source: '"a" + "b"', result: 'ab'
|
||||
}, {
|
||||
source: 'Math.floor(Math.PI)', result: 3
|
||||
}, {
|
||||
source: 'ol', result: ol
|
||||
}, {
|
||||
source: 'this', result: goog.global
|
||||
}];
|
||||
|
||||
var c, exp;
|
||||
for (var i = 0, ii = cases.length; i < ii; ++i) {
|
||||
c = cases[i];
|
||||
exp = new ol.Expression(c.source);
|
||||
expect(exp.evaluate()).to.be(c.result);
|
||||
}
|
||||
});
|
||||
|
||||
it('accepts an optional this argument', function() {
|
||||
function Thing() {
|
||||
this.works = true;
|
||||
};
|
||||
|
||||
var exp = new ol.Expression('this.works ? "yes" : "no"');
|
||||
expect(exp.evaluate(new Thing())).to.be('yes');
|
||||
expect(exp.evaluate({})).to.be('no');
|
||||
});
|
||||
|
||||
it('accepts an optional scope argument', function() {
|
||||
var exp;
|
||||
var scope = {
|
||||
greeting: 'hello world',
|
||||
punctuation: '!',
|
||||
pick: function(array, index) {
|
||||
return array[index];
|
||||
}
|
||||
};
|
||||
|
||||
// access two members in the scope
|
||||
exp = new ol.Expression('greeting + punctuation');
|
||||
expect(exp.evaluate({}, scope)).to.be('hello world!');
|
||||
|
||||
// call a function in the scope
|
||||
exp = new ol.Expression(
|
||||
'pick([10, 42, "chicken"], 2) + Math.floor(Math.PI)');
|
||||
expect(exp.evaluate({}, scope)).to.be('chicken3');
|
||||
|
||||
});
|
||||
|
||||
it('throws on error', function() {
|
||||
var exp = new ol.Expression('@*)$(&');
|
||||
expect(function() {exp.evaluate()}).to.throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
@@ -107,7 +107,7 @@ describe('ol.layer.Vector', function() {
|
||||
symbolizers: [
|
||||
new ol.style.Line({
|
||||
strokeWidth: 2,
|
||||
strokeColor: new ol.Expression('colorProperty'),
|
||||
strokeColor: ol.expression.parse('colorProperty'),
|
||||
opacity: 1
|
||||
})
|
||||
]
|
||||
@@ -144,7 +144,7 @@ describe('ol.layer.Vector', function() {
|
||||
it('groups equal symbolizers also when defined on features', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
strokeWidth: 3,
|
||||
strokeColor: new ol.Expression('colorProperty'),
|
||||
strokeColor: ol.expression.parse('colorProperty'),
|
||||
opacity: 1
|
||||
});
|
||||
var anotherSymbolizer = new ol.style.Line({
|
||||
@@ -177,8 +177,8 @@ describe('ol.layer.Vector', function() {
|
||||
});
|
||||
|
||||
goog.require('goog.dispose');
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expression');
|
||||
goog.require('ol.filter.Extent');
|
||||
goog.require('ol.filter.Geometry');
|
||||
goog.require('ol.filter.Logical');
|
||||
|
||||
@@ -42,8 +42,8 @@ describe('ol.style.Line', function() {
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
strokeWidth: ol.Expression('widthAttr')
|
||||
opacity: ol.expression.parse('value / 100'),
|
||||
strokeWidth: ol.expression.parse('widthAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Line);
|
||||
});
|
||||
@@ -54,8 +54,8 @@ describe('ol.style.Line', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Line({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
strokeWidth: ol.Expression('widthAttr')
|
||||
opacity: ol.expression.parse('value / 100'),
|
||||
strokeWidth: ol.expression.parse('widthAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
@@ -73,7 +73,7 @@ describe('ol.style.Line', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expression');
|
||||
goog.require('ol.style.Line');
|
||||
goog.require('ol.style.LineLiteral');
|
||||
|
||||
@@ -45,8 +45,8 @@ describe('ol.style.Polygon', function() {
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
fillColor: new ol.Expression('fillAttr')
|
||||
opacity: ol.expression.parse('value / 100'),
|
||||
fillColor: ol.expression.parse('fillAttr')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Polygon);
|
||||
});
|
||||
@@ -57,8 +57,8 @@ describe('ol.style.Polygon', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Polygon({
|
||||
opacity: new ol.Expression('value / 100'),
|
||||
fillColor: new ol.Expression('fillAttr')
|
||||
opacity: ol.expression.parse('value / 100'),
|
||||
fillColor: ol.expression.parse('fillAttr')
|
||||
});
|
||||
|
||||
var feature = new ol.Feature({
|
||||
@@ -89,7 +89,7 @@ describe('ol.style.Polygon', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expression');
|
||||
goog.require('ol.style.Polygon');
|
||||
goog.require('ol.style.PolygonLiteral');
|
||||
|
||||
@@ -51,8 +51,8 @@ describe('ol.style.Shape', function() {
|
||||
|
||||
it('accepts expressions', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
strokeColor: new ol.Expression('color')
|
||||
size: ol.expression.parse('sizeAttr'),
|
||||
strokeColor: ol.expression.parse('color')
|
||||
});
|
||||
expect(symbolizer).to.be.a(ol.style.Shape);
|
||||
});
|
||||
@@ -63,8 +63,8 @@ describe('ol.style.Shape', function() {
|
||||
|
||||
it('evaluates expressions with the given feature', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
opacity: new ol.Expression('opacityAttr'),
|
||||
size: ol.expression.parse('sizeAttr'),
|
||||
opacity: ol.expression.parse('opacityAttr'),
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
|
||||
@@ -99,8 +99,8 @@ describe('ol.style.Shape', function() {
|
||||
|
||||
it('applies default type if none provided', function() {
|
||||
var symbolizer = new ol.style.Shape({
|
||||
size: new ol.Expression('sizeAttr'),
|
||||
opacity: new ol.Expression('opacityAttr'),
|
||||
size: ol.expression.parse('sizeAttr'),
|
||||
opacity: ol.expression.parse('opacityAttr'),
|
||||
fillColor: '#BADA55'
|
||||
});
|
||||
|
||||
@@ -119,8 +119,8 @@ describe('ol.style.Shape', function() {
|
||||
|
||||
});
|
||||
|
||||
goog.require('ol.Expression');
|
||||
goog.require('ol.Feature');
|
||||
goog.require('ol.expression');
|
||||
goog.require('ol.style.Shape');
|
||||
goog.require('ol.style.ShapeLiteral');
|
||||
goog.require('ol.style.ShapeType');
|
||||
|
||||
Reference in New Issue
Block a user