import { AsyncTestCompleter, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit } from 'angular2/testing_internal'; import {HtmlAst} from 'angular2/src/compiler/html_ast'; import {Message, id} from 'angular2/src/i18n/message'; import {serializeXmb, deserializeXmb} from 'angular2/src/i18n/xmb_serializer'; import {ParseSourceSpan, ParseError} from 'angular2/src/compiler/parse_util'; export function main() { describe("Xmb", () => { describe('Xmb Serialization', () => { it("should return an empty message bundle for an empty list of messages", () => { expect(serializeXmb([])).toEqual(""); }); it("should serializeXmb messages without desc", () => { let m = new Message("content", "meaning", null); let expected = `content`; expect(serializeXmb([m])).toEqual(expected); }); it("should serializeXmb messages with desc", () => { let m = new Message("content", "meaning", "description"); let expected = `content`; expect(serializeXmb([m])).toEqual(expected); }); }); describe("Xmb Deserialization", () => { it("should parse an empty bundle", () => { let mb = ""; expect(deserializeXmb(mb, "url").messages).toEqual({}); }); it("should parse an non-empty bundle", () => { let mb = ` content1 content2 `; let parsed = deserializeXmb(mb, "url").messages; expect(_serialize(parsed["id1"])).toEqual("content1"); expect(_serialize(parsed["id2"])).toEqual("content2"); }); it("should error when cannot parse the content", () => { let mb = ` content `; let res = deserializeXmb(mb, "url"); expect(_serializeErrors(res.errors)).toEqual(['Unexpected closing tag "message-bundle"']); }); it("should error when cannot find the id attribute", () => { let mb = ` content `; let res = deserializeXmb(mb, "url"); expect(_serializeErrors(res.errors)).toEqual(['"id" attribute is missing']); }); it("should error on empty content", () => { let mb = ``; let res = deserializeXmb(mb, "url"); expect(_serializeErrors(res.errors)).toEqual(['Missing element "message-bundle"']); }); it("should error on an invalid element", () => { let mb = ` content `; let res = deserializeXmb(mb, "url"); expect(_serializeErrors(res.errors)).toEqual(['Unexpected element "invalid"']); }); it("should expand 'ph' elements", () => { let mb = ` a `; let res = deserializeXmb(mb, "url").messages["id1"]; expect((res[1]).name).toEqual("ph"); }); }); }); } function _serialize(nodes: HtmlAst[]): string { return (nodes[0]).value; } function _serializeErrors(errors: ParseError[]): string[] { return errors.map(e => e.msg); }