Test left-hand-side expression parsing

This commit is contained in:
Tim Schaub
2013-06-11 11:37:17 -06:00
parent 13d0b8b084
commit d920d8e578
2 changed files with 46 additions and 5 deletions

View File

@@ -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();
});
});
});