feat(Parser): implement Parser
Add a simple parser implementation that supports only field reads.
This commit is contained in:
38
modules/change_detection/test/parser/parser_spec.js
Normal file
38
modules/change_detection/test/parser/parser_spec.js
Normal file
@ -0,0 +1,38 @@
|
||||
import {ddescribe, describe, it, expect, beforeEach} from 'test_lib/test_lib';
|
||||
import {Parser} from 'change_detection/parser/parser';
|
||||
import {Lexer} from 'change_detection/parser/lexer';
|
||||
import {ClosureMap} from 'change_detection/parser/closure_map';
|
||||
|
||||
class TestData {
|
||||
constructor(a) {
|
||||
this.a = a;
|
||||
}
|
||||
}
|
||||
|
||||
export function main() {
|
||||
function td({a}) {
|
||||
return new TestData(a);
|
||||
}
|
||||
|
||||
describe("parser", () => {
|
||||
describe("field access", () => {
|
||||
var parser;
|
||||
|
||||
beforeEach(() => {
|
||||
parser = new Parser(new Lexer(), new ClosureMap());
|
||||
});
|
||||
|
||||
it("should parse field access",() => {
|
||||
var exp = parser.parse("a");
|
||||
var context = td({a: 999});
|
||||
expect(exp.eval(context)).toEqual(999);
|
||||
});
|
||||
|
||||
it("should parse nested field access",() => {
|
||||
var exp = parser.parse("a.a");
|
||||
var context = td({a: td({a: 999})});
|
||||
expect(exp.eval(context)).toEqual(999);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user