1+ import {
2+ ComponentFixture ,
3+ AsyncTestCompleter ,
4+ TestComponentBuilder ,
5+ beforeEach ,
6+ ddescribe ,
7+ xdescribe ,
8+ describe ,
9+ el ,
10+ expect ,
11+ iit ,
12+ inject ,
13+ beforeEachProviders ,
14+ it ,
15+ xit
16+ } from 'angular2/testing_internal' ;
17+
18+ import { DefaultRouterUrlSerializer } from 'angular2/src/alt_router/router_url_serializer' ;
19+ import { UrlSegment } from 'angular2/src/alt_router/segments' ;
20+
21+ export function main ( ) {
22+ describe ( 'url parsing' , ( ) => {
23+ let url = new DefaultRouterUrlSerializer ( ) ;
24+
25+ it ( 'should throw on an empty urls' , ( ) => { expect ( ( ) => url . parse ( "" ) ) . toThrow ( ) ; } ) ;
26+
27+ it ( 'should parse the root url' , ( ) => {
28+ let tree = url . parse ( "/" ) ;
29+ expectSegment ( tree . root , "" ) ;
30+ expect ( url . serialize ( tree ) ) . toEqual ( "" ) ;
31+ } ) ;
32+
33+ it ( 'should parse non-empty urls' , ( ) => {
34+ let tree = url . parse ( "one/two" ) ;
35+ expectSegment ( tree . firstChild ( tree . root ) , "one" ) ;
36+ expectSegment ( tree . firstChild ( tree . firstChild ( tree . root ) ) , "two" ) ;
37+ expect ( url . serialize ( tree ) ) . toEqual ( "/one/two" ) ;
38+ } ) ;
39+
40+ it ( "should parse multiple aux routes" , ( ) => {
41+ let tree = url . parse ( "/one/two(/three//right:four)/five" ) ;
42+ let c = tree . children ( tree . firstChild ( tree . root ) ) ;
43+
44+ expectSegment ( c [ 0 ] , "two" ) ;
45+ expectSegment ( c [ 1 ] , "aux:three" ) ;
46+ expectSegment ( c [ 2 ] , "right:four" ) ;
47+
48+ expectSegment ( tree . firstChild ( c [ 0 ] ) , "five" ) ;
49+
50+ expect ( url . serialize ( tree ) ) . toEqual ( "/one/two(aux:three//right:four)/five" ) ;
51+ } ) ;
52+
53+ it ( "should parse aux routes that have aux routes" , ( ) => {
54+ let tree = url . parse ( "/one(/two(/three))" ) ;
55+ let c = tree . children ( tree . root ) ;
56+
57+ expectSegment ( c [ 0 ] , "one" ) ;
58+ expectSegment ( c [ 1 ] , "aux:two" ) ;
59+ expectSegment ( c [ 2 ] , "aux:three" ) ;
60+
61+ expect ( url . serialize ( tree ) ) . toEqual ( "/one(aux:two//aux:three)" ) ;
62+ } ) ;
63+
64+ it ( "should parse aux routes that have children" , ( ) => {
65+ let tree = url . parse ( "/one(/two/three)" ) ;
66+ let c = tree . children ( tree . root ) ;
67+
68+ expectSegment ( c [ 0 ] , "one" ) ;
69+ expectSegment ( c [ 1 ] , "aux:two" ) ;
70+ expectSegment ( tree . firstChild ( c [ 1 ] ) , "three" ) ;
71+
72+ expect ( url . serialize ( tree ) ) . toEqual ( "/one(aux:two/three)" ) ;
73+ } ) ;
74+
75+ it ( "should parse an empty aux route definition" , ( ) => {
76+ let tree = url . parse ( "/one()" ) ;
77+ let c = tree . children ( tree . root ) ;
78+
79+ expectSegment ( c [ 0 ] , "one" ) ;
80+ expect ( tree . children ( c [ 0 ] ) . length ) . toEqual ( 0 ) ;
81+
82+ expect ( url . serialize ( tree ) ) . toEqual ( "/one" ) ;
83+ } ) ;
84+
85+ it ( "should parse key-value matrix params" , ( ) => {
86+ let tree = url . parse ( "/one;a=11a;b=11b(/two;c=22//right:three;d=33)" ) ;
87+
88+ let c = tree . firstChild ( tree . root ) ;
89+ expectSegment ( c , "one" ) ;
90+
91+ let c2 = tree . children ( c ) ;
92+ expectSegment ( c2 [ 0 ] , ";a=11a;b=11b" ) ;
93+ expectSegment ( c2 [ 1 ] , "aux:two" ) ;
94+ expectSegment ( c2 [ 2 ] , "right:three" ) ;
95+
96+ expectSegment ( tree . firstChild ( c2 [ 1 ] ) , ";c=22" ) ;
97+ expectSegment ( tree . firstChild ( c2 [ 2 ] ) , ";d=33" ) ;
98+
99+ expect ( url . serialize ( tree ) ) . toEqual ( "/one;a=11a;b=11b(aux:two;c=22//right:three;d=33)" ) ;
100+ } ) ;
101+
102+ it ( "should parse key only matrix params" , ( ) => {
103+ let tree = url . parse ( "/one;a" ) ;
104+
105+ let c = tree . firstChild ( tree . root ) ;
106+ expectSegment ( c , "one" ) ;
107+ expectSegment ( tree . firstChild ( c ) , ";a=true" ) ;
108+
109+ expect ( url . serialize ( tree ) ) . toEqual ( "/one;a=true" ) ;
110+ } ) ;
111+
112+ // it("should parse key-value query params", () => {
113+ // let tree = url.parse("/one?a=1&b=2");
114+ // expect(tree.root).toEqual(new UrlSegment("", {'a': '1', 'b': '2'}, DEFAULT_OUTLET_NAME));
115+ // });
116+ //
117+ // it("should parse key only query params", () => {
118+ // let tree = url.parse("/one?a");
119+ // expect(tree.root).toEqual(new UrlSegment("", {'a': "true"}, DEFAULT_OUTLET_NAME));
120+ // });
121+ //
122+ // it("should parse a url with only query params", () => {
123+ // let tree = url.parse("?a");
124+ // expect(tree.root).toEqual(new UrlSegment("", {'a': "true"}, DEFAULT_OUTLET_NAME));
125+ // });
126+ //
127+ // it("should allow slashes within query params", () => {
128+ // let tree = url.parse("?a=http://boo");
129+ // expect(tree.root).toEqual(new UrlSegment("", {'a': "http://boo"}, DEFAULT_OUTLET_NAME));
130+ // });
131+ } ) ;
132+ }
133+
134+ function expectSegment ( segment : UrlSegment , expected : string ) : void {
135+ expect ( segment . toString ( ) ) . toEqual ( expected ) ;
136+ }
0 commit comments