import { ddescribe, describe, xdescribe, it, iit, xit, expect, beforeEach, afterEach, AsyncTestCompleter, inject } from 'angular2/test_lib'; import {IS_DART} from '../platform'; import {CONST_EXPR, stringify, isType, Type, isBlank} from 'angular2/src/core/facade/lang'; import {PromiseWrapper, Promise} from 'angular2/src/core/facade/async'; import {HtmlParser} from 'angular2/src/compiler/html_parser'; import {TemplateParser} from 'angular2/src/compiler/template_parser'; import {MockSchemaRegistry} from './template_parser_spec'; import {Parser, Lexer} from 'angular2/src/core/change_detection/change_detection'; import { CommandVisitor, TextCmd, NgContentCmd, BeginElementCmd, BeginComponentCmd, EmbeddedTemplateCmd, TemplateCmd, visitAllCommands, CompiledTemplate } from 'angular2/src/core/compiler/template_commands'; import {CommandCompiler} from 'angular2/src/compiler/command_compiler'; import { DirectiveMetadata, TypeMetadata, TemplateMetadata, SourceModule } from 'angular2/src/compiler/api'; import {ViewEncapsulation} from 'angular2/src/core/render/api'; import {evalModule} from './eval_module'; import {escapeSingleQuoteString} from 'angular2/src/compiler/util'; const BEGIN_ELEMENT = 'BEGIN_ELEMENT'; const END_ELEMENT = 'END_ELEMENT'; const BEGIN_COMPONENT = 'BEGIN_COMPONENT'; const END_COMPONENT = 'END_COMPONENT'; const TEXT = 'TEXT'; const NG_CONTENT = 'NG_CONTENT'; const EMBEDDED_TEMPLATE = 'EMBEDDED_TEMPLATE'; // Attention: These module names have to correspond to real modules! const MODULE_NAME = 'angular2/test/compiler/command_compiler_spec'; const TEMPLATE_COMMANDS_MODULE_NAME = 'angular2/src/core/compiler/template_commands'; // Attention: read by eval! export class RootComp {} export class SomeDir {} export class AComp {} var RootCompTypeMeta = new TypeMetadata({typeName: 'RootComp', id: 1, type: RootComp, typeUrl: MODULE_NAME}); var SomeDirTypeMeta = new TypeMetadata({typeName: 'SomeDir', id: 2, type: SomeDir, typeUrl: MODULE_NAME}); var ACompTypeMeta = new TypeMetadata({typeName: 'AComp', id: 3, type: AComp, typeUrl: MODULE_NAME}); var NESTED_COMPONENT = new CompiledTemplate('someNestedComponentId', []); export function main() { describe('CommandCompiler', () => { var domParser: HtmlParser; var parser: TemplateParser; var commandCompiler: CommandCompiler; var componentTemplateFactory: Function; beforeEach(() => { domParser = new HtmlParser(); parser = new TemplateParser( new Parser(new Lexer()), new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})); commandCompiler = new CommandCompiler(); }); function createComp({type, selector, template, encapsulation, ngContentSelectors}: { type?: TypeMetadata, selector?: string, template?: string, encapsulation?: ViewEncapsulation, ngContentSelectors?: string[] }): DirectiveMetadata { if (isBlank(encapsulation)) { encapsulation = ViewEncapsulation.None; } if (isBlank(selector)) { selector = 'root'; } if (isBlank(ngContentSelectors)) { ngContentSelectors = []; } if (isBlank(template)) { template = ''; } return new DirectiveMetadata({ selector: selector, isComponent: true, type: type, template: new TemplateMetadata({ template: template, ngContentSelectors: ngContentSelectors, encapsulation: encapsulation }) }); } function createDirective(type: TypeMetadata, selector: string): DirectiveMetadata { return new DirectiveMetadata({selector: selector, isComponent: false, type: type}); } function createTests(run: Function) { describe('text', () => { it('should create unbound text commands', inject([AsyncTestCompleter], (async) => { var rootComp = createComp({type: RootCompTypeMeta, template: 'a'}); run(rootComp, []) .then((data) => { expect(data).toEqual([[TEXT, 'a', false, null]]); async.done(); }); })); it('should create bound text commands', inject([AsyncTestCompleter], (async) => { var rootComp = createComp({type: RootCompTypeMeta, template: '{{a}}'}); run(rootComp, []) .then((data) => { expect(data).toEqual([[TEXT, null, true, null]]); async.done(); }); })); }); describe('elements', () => { it('should create unbound element commands', inject([AsyncTestCompleter], (async) => { var rootComp = createComp({type: RootCompTypeMeta, template: '