New ThisIdentifier expression
This allows member expressions to use the 'this' keyword.
This commit is contained in:
@@ -92,6 +92,12 @@ describe('ol.expr.parse()', function() {
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('parses member expressions in the \'this\' scope', function() {
|
||||
var expr = ol.expr.parse('this.foo');
|
||||
var thisScope = {foo: 'bar'};
|
||||
expect(expr.evaluate(undefined, undefined, thisScope)).to.be('bar');
|
||||
});
|
||||
|
||||
it('consumes whitespace as expected', function() {
|
||||
var expr = ol.expr.parse(' foo . bar . baz ');
|
||||
expect(expr).to.be.a(ol.expr.Member);
|
||||
|
||||
@@ -624,6 +624,25 @@ describe('ol.expr.Not', function() {
|
||||
});
|
||||
|
||||
|
||||
describe('ol.expr.ThisIdentifier', function() {
|
||||
|
||||
describe('#getInstance()', function() {
|
||||
it('has a getInstance method to return the singleton', function() {
|
||||
expect(ol.expr.ThisIdentifier.getInstance())
|
||||
.to.be.a(ol.expr.ThisIdentifier);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#evaluate()', function() {
|
||||
it('evaluates to the passed scope', function() {
|
||||
expect(ol.expr.ThisIdentifier.getInstance()
|
||||
.evaluate(undefined, undefined, 'foo')).to.be('foo');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.expr.Call');
|
||||
goog.require('ol.expr.Comparison');
|
||||
goog.require('ol.expr.ComparisonOp');
|
||||
@@ -636,3 +655,4 @@ goog.require('ol.expr.Math');
|
||||
goog.require('ol.expr.MathOp');
|
||||
goog.require('ol.expr.Member');
|
||||
goog.require('ol.expr.Not');
|
||||
goog.require('ol.expr.ThisIdentifier');
|
||||
|
||||
Reference in New Issue
Block a user