angular-docs-cn/packages/compiler/test/ml_parser/ast_serializer_spec.ts

63 lines
1.9 KiB
TypeScript
Raw Normal View History

2016-07-21 16:56:58 -04:00
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
import {serializeNodes} from './util/util';
2016-07-01 20:30:09 -04:00
{
2016-08-01 17:43:20 -04:00
describe('Node serializer', () => {
let parser: HtmlParser;
2016-07-01 20:30:09 -04:00
beforeEach(() => {
parser = new HtmlParser();
});
2016-07-01 20:30:09 -04:00
it('should support element', () => {
const html = '<p></p>';
const ast = parser.parse(html, 'url');
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
it('should support attributes', () => {
const html = '<p k="value"></p>';
const ast = parser.parse(html, 'url');
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
it('should support text', () => {
const html = 'some text';
const ast = parser.parse(html, 'url');
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
it('should support expansion', () => {
const html = '{number, plural, =0 {none} =1 {one} other {many}}';
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
it('should support comment', () => {
const html = '<!--comment-->';
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
it('should support nesting', () => {
const html = `<div i18n="meaning|desc">
<span>{{ interpolation }}</span>
<!--comment-->
<p expansion="true">
2016-11-04 18:10:19 -04:00
{number, plural, =0 {{sex, select, other {<b>?</b>}}}}
</p>
2016-07-01 20:30:09 -04:00
</div>`;
const ast = parser.parse(html, 'url', {tokenizeExpansionForms: true});
2016-08-01 17:43:20 -04:00
expect(serializeNodes(ast.rootNodes)).toEqual([html]);
2016-07-01 20:30:09 -04:00
});
});
}