Test left-hand-side expression parsing
This commit is contained in:
@@ -61,6 +61,44 @@ describe('ol.expression.parse', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('left-hand-side expressions', function() {
|
||||
// http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
|
||||
|
||||
it('parses member expressions with dot notation', function() {
|
||||
var expr = ol.expression.parse('foo.bar.baz');
|
||||
expect(expr).to.be.a(ol.expression.Member);
|
||||
var scope = {foo: {bar: {baz: 42}}};
|
||||
expect(expr.evaluate(scope)).to.be(42);
|
||||
});
|
||||
|
||||
it('throws on invalid member expression', function() {
|
||||
expect(function() {
|
||||
ol.expression.parse('foo.4bar');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('parses call expressions with literal arguments', function() {
|
||||
var expr = ol.expression.parse('foo(42, "bar")');
|
||||
expect(expr).to.be.a(ol.expression.Call);
|
||||
var scope = {
|
||||
foo: function(num, str) {
|
||||
expect(num).to.be(42);
|
||||
expect(str).to.be('bar');
|
||||
return str + num;
|
||||
}
|
||||
};
|
||||
expect(expr.evaluate(scope)).to.be('bar42');
|
||||
});
|
||||
|
||||
it('throws on calls with unterminated arguments', function() {
|
||||
expect(function() {
|
||||
ol.expression.parse('foo(42,)');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user