feat(router): implement RouterUrlParser

This commit is contained in:
vsavkin
2016-04-22 12:04:40 -07:00
committed by Victor Savkin
parent 90a1f7d5c4
commit f6985671dd
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,45 @@
import {
ComponentFixture,
AsyncTestCompleter,
TestComponentBuilder,
beforeEach,
ddescribe,
xdescribe,
describe,
el,
expect,
iit,
inject,
beforeEachProviders,
it,
xit
} from 'angular2/testing_internal';
import {DefaultRouterUrlParser} from 'angular2/src/alt_router/router_url_parser';
import {UrlSegment} from 'angular2/src/alt_router/segments';
export function main() {
describe('url parsing', () => {
let parser = new DefaultRouterUrlParser();
it('should throw on an empty urls', () => { expect(() => parser.parse("")).toThrow(); });
it('should parse the root url', () => {
let tree = parser.parse("/");
expect(tree.root).toEqual(new UrlSegment("/", {}, ""));
});
it('should parse non-empty urls', () => {
let tree = parser.parse("one/two/three");
expect(tree.root).toEqual(new UrlSegment("one", {}, ""));
expect(tree.firstChild(tree.root)).toEqual(new UrlSegment("two", {}, ""));
expect(tree.firstChild(tree.firstChild(tree.root))).toEqual(new UrlSegment("three", {}, ""));
});
it('should parse non-empty absolute urls', () => {
let tree = parser.parse("/one/two");
expect(tree.root).toEqual(new UrlSegment("/one", {}, ""));
expect(tree.firstChild(tree.root)).toEqual(new UrlSegment("two", {}, ""));
});
});
}