refactor(i18n): misc updates

This commit is contained in:
Victor Berchet
2016-08-01 14:43:20 -07:00
parent df44e3e425
commit e811a5d97f
10 changed files with 115 additions and 59 deletions

View File

@ -11,7 +11,7 @@ import * as html from '../../src/ml_parser/ast';
import {HtmlParser} from '../../src/ml_parser/html_parser';
export function main() {
describe('Node serilaizer', () => {
describe('Node serializer', () => {
var parser: HtmlParser;
beforeEach(() => { parser = new HtmlParser(); });
@ -19,31 +19,31 @@ export function main() {
it('should support element', () => {
const html = '<p></p>';
const ast = parser.parse(html, 'url');
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support attributes', () => {
const html = '<p k="value"></p>';
const ast = parser.parse(html, 'url');
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support text', () => {
const html = 'some text';
const ast = parser.parse(html, 'url');
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support expansion', () => {
const html = '{number, plural, =0 {none} =1 {one} other {many}}';
const ast = parser.parse(html, 'url', true);
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support comment', () => {
const html = '<!--comment-->';
const ast = parser.parse(html, 'url', true);
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
it('should support nesting', () => {
@ -55,7 +55,7 @@ export function main() {
</p>
</div>`;
const ast = parser.parse(html, 'url', true);
expect(serializeAst(ast.rootNodes)).toEqual([html]);
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
});
});
}
@ -91,6 +91,6 @@ class _SerializerVisitor implements html.Visitor {
const serializerVisitor = new _SerializerVisitor();
export function serializeAst(nodes: html.Node[]): string[] {
export function serializeNodes(nodes: html.Node[]): string[] {
return nodes.map(node => node.visit(serializerVisitor, null));
}