feat(change_detection): change binding syntax to explicitly specify pipes

This commit is contained in:
vsavkin
2015-02-19 17:47:25 -08:00
parent 69e02ee76f
commit 58ba700b14
20 changed files with 236 additions and 101 deletions

View File

@ -51,6 +51,10 @@ export function main() {
return createParser().parseInterpolation(text, location);
}
function addPipes(ast, pipes) {
return createParser().addPipes(ast, pipes);
}
function expectEval(text, passedInContext = null) {
var c = isBlank(passedInContext) ? td() : passedInContext;
return expect(parseAction(text).eval(c));
@ -544,6 +548,29 @@ export function main() {
});
});
describe('addPipes', () => {
it('should return the given ast whe the list of pipes is empty', () => {
var ast = parseBinding("1 + 1", "Location");
var transformedAst = addPipes(ast, []);
expect(transformedAst).toBe(ast);
});
it('should append pipe ast nodes', () => {
var ast = parseBinding("1 + 1", "Location");
var transformedAst = addPipes(ast, ['one', 'two']);
expect(transformedAst.ast.name).toEqual("two");
expect(transformedAst.ast.exp.name).toEqual("one");
expect(transformedAst.ast.exp.exp.operation).toEqual("+");
});
it('should preserve location and source', () => {
var ast = parseBinding("1 + 1", "Location");
var transformedAst = addPipes(ast, ['one', 'two']);
expect(transformedAst.source).toEqual("1 + 1");
expect(transformedAst.location).toEqual("Location");
});
});
describe('wrapLiteralPrimitive', () => {
it('should wrap a literal primitive', () => {
expect(createParser().wrapLiteralPrimitive("foo", null).eval(null)).toEqual("foo");