Scanning identifiers
This includes code that is likely not necessary. The escape sequence scanning will likely not be used in our case, but I'm committing it here so it can be brought back if needed later.
This commit is contained in:
@@ -9,10 +9,97 @@ describe('ol.expression.Lexer', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#scanIdentifier_()', function() {
|
||||
|
||||
function scan(source) {
|
||||
var lexer = new ol.expression.Lexer(source);
|
||||
return lexer.scanIdentifier_();
|
||||
}
|
||||
|
||||
it('works for short identifiers', function() {
|
||||
var token = scan('a');
|
||||
expect(token.value).to.be('a');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for longer identifiers', function() {
|
||||
var token = scan('foo');
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for $ anywhere', function() {
|
||||
var token = scan('$foo$bar$');
|
||||
expect(token.value).to.be('$foo$bar$');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for _ anywhere', function() {
|
||||
var token = scan('_foo_bar_');
|
||||
expect(token.value).to.be('_foo_bar_');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works for keywords', function() {
|
||||
var token = scan('delete');
|
||||
expect(token.value).to.be('delete');
|
||||
expect(token.type).to.be(ol.expression.TokenType.KEYWORD);
|
||||
});
|
||||
|
||||
it('works for null', function() {
|
||||
var token = scan('null');
|
||||
expect(token.value).to.be('null');
|
||||
expect(token.type).to.be(ol.expression.TokenType.NULL_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean true', function() {
|
||||
var token = scan('true');
|
||||
expect(token.value).to.be('true');
|
||||
expect(token.type).to.be(ol.expression.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works for boolean false', function() {
|
||||
var token = scan('false');
|
||||
expect(token.value).to.be('false');
|
||||
expect(token.type).to.be(ol.expression.TokenType.BOOLEAN_LITERAL);
|
||||
});
|
||||
|
||||
it('works with unicode escape sequences', function() {
|
||||
var token = scan('\u006f\u006c\u0033');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('works with hex escape sequences', function() {
|
||||
var token = scan('\x6f\x6c\x33');
|
||||
expect(token.value).to.be('ol3');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a number', function() {
|
||||
expect(function() {
|
||||
scan('4foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('throws for identifiers starting with a punctuation char', function() {
|
||||
expect(function() {
|
||||
scan('!foo');
|
||||
}).throwException();
|
||||
});
|
||||
|
||||
it('only scans valid identifier part', function() {
|
||||
var token = scan('foo>bar');
|
||||
expect(token.value).to.be('foo');
|
||||
expect(token.type).to.be(ol.expression.TokenType.IDENTIFIER);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#scanNumericLiteral_()', function() {
|
||||
|
||||
function scan(code) {
|
||||
var lexer = new ol.expression.Lexer(code);
|
||||
function scan(source) {
|
||||
var lexer = new ol.expression.Lexer(source);
|
||||
return lexer.scanNumericLiteral_();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user