2
* This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
10
class URITest extends haxe.unit.TestCaseX
12
public function testParseAbsolute()
14
var uri = URI.parsed( "http://user:pass@somewhere.com:22/pa%20th/to/file.txt?query=one#frag" );
16
assertEquals( "http", uri.scheme );
17
assertEquals( "user:pass@somewhere.com:22", uri.authority );
18
assertEquals( "/pa th/to/file.txt", uri.path );
19
assertEquals( "query=one", uri.query );
20
assertEquals( "frag", uri.fragment );
21
assertFalse( uri.isRelative() );
24
assertEquals( "user:pass", uri.userinfo );
25
assertEquals( "somewhere.com", uri.host );
26
assertEquals( "22", uri.port );
27
assertEquals( "/pa th/to/", uri.pathdir );
28
assertEquals( "file.txt", uri.filename );
31
assertEquals( "http://user:pass@somewhere.com:22/pa th/to/file.txt?query=one#frag", uri.exportFromNormal() );
33
//extremely short test
34
uri = URI.parsed( "ft%70://%74ommy.com" );
35
assertEquals( "ftp", uri.scheme );
36
assertEquals( "tommy.com", uri.authority );
37
assertEquals( "", uri.path );
38
assertNull( uri.query );
39
assertNull( uri.fragment );
41
//absent details check
42
assertNull( uri.userinfo );
43
assertNull( uri.port );
44
assertEquals( "", uri.pathdir );
45
assertEquals( "", uri.filename );
47
assertEquals( "ftp://tommy.com", uri.exportFromNormal() );
48
assertEquals( "ft%70://%74ommy.com", uri.exportFromRaw() );
51
uri = URI.parsed( "file://server/../.p%3Fath/file.doc", "ascii" );
52
assertEquals( "file", uri.scheme );
53
assertEquals( "server", uri.authority );
54
assertEquals( "/.p?ath/file.doc", uri.path );
55
assertEquals( "/.p%3Fath/file.doc", uri.pathRaw );
56
assertNull( uri.query );
57
assertNull( uri.fragment );
59
assertEquals( "file://server/.p%3Fath/file.doc", uri.exportFromNormal() );
62
uri = URI.parsed( "file:///tmp/./..out/sub/../T%C3%80st%E3%82%A2.swf" );
63
assertEquals( "file", uri.scheme );
64
assertEquals( "", uri.authority );
65
assertEquals( "/tmp/..out/TÀstア.swf", uri.path );
67
assertEquals( "file:///tmp/..out/TÀstア.swf", uri.exportFromNormal() );
70
uri = URI.parsed( "urn:isbn:0451450523" );
71
assertEquals( "urn", uri.scheme );
72
assertEquals( "isbn", uri.namespaceID );
73
assertEquals( "0451450523", uri.namespaceString );
74
assertEquals( "urn:isbn:0451450523", uri.toString() );
76
assertNull( uri.authority );
77
assertNull( uri.query );
78
assertNull( uri.fragment );
81
public function testParseRelative()
83
var uri = URI.parsed( "/quick/now?query", true );
84
assertEquals( "/quick/now", uri.path );
85
assertEquals( "query", uri.query );
86
assertEquals( "/quick/now?query", uri.toString() );
87
assertTrue( uri.isRelative() );
90
public function testReference()
92
//taken from 5.4 in the RFC
93
var base = URI.parsed( "http://a/b/c/d;p?q" );
94
assertEquals( "http://a/b/c/d;p?q", base.toString() );
98
[ "g" , "http://a/b/c/g" ],
99
[ "./g" , "http://a/b/c/g" ],
100
[ "g/" , "http://a/b/c/g/" ],
101
[ "/g" , "http://a/g" ],
102
[ "//g" , "http://g" ],
103
[ "?y" , "http://a/b/c/d;p?y" ],
104
[ "g?y" , "http://a/b/c/g?y" ],
105
[ "#s" , "http://a/b/c/d;p?q#s" ],
106
[ "g#s" , "http://a/b/c/g#s" ],
107
[ "g?y#s" , "http://a/b/c/g?y#s" ],
108
[ ";x" , "http://a/b/c/;x" ],
109
[ "g;x" , "http://a/b/c/g;x" ],
110
[ "g;x?y#s" , "http://a/b/c/g;x?y#s" ],
111
[ "" , "http://a/b/c/d;p?q" ],
112
[ "." , "http://a/b/c/" ],
113
[ "./" , "http://a/b/c/" ],
114
[ ".." , "http://a/b/" ],
115
[ "../" , "http://a/b/" ],
116
[ "../g" , "http://a/b/g" ],
117
[ "../.." , "http://a/" ],
118
[ "../../" , "http://a/" ],
119
[ "../../g" , "http://a/g" ],
122
["../../../g" , "http://a/g"],
123
["../../../../g" , "http://a/g"],
126
[ "/./g" , "http://a/g"],
127
["/../g" , "http://a/g"],
128
["g." , "http://a/b/c/g."],
129
[".g" , "http://a/b/c/.g"],
130
["g.." , "http://a/b/c/g.."],
131
["..g" , "http://a/b/c/..g"],
134
["./../g" , "http://a/b/g"],
135
["./g/." , "http://a/b/c/g/"],
136
["g/./h" , "http://a/b/c/g/h"],
137
["g/../h" , "http://a/b/c/h"],
138
["g;x=1/./y" , "http://a/b/c/g;x=1/y"],
139
["g;x=1/../y" , "http://a/b/c/y"],
142
["g?y/./x" , "http://a/b/c/g?y/./x"],
143
["g?y/../x" , "http://a/b/c/g?y/../x"],
144
["g#s/./x" , "http://a/b/c/g#s/./x"],
145
["g#s/../x" , "http://a/b/c/g#s/../x"],
148
[ "http:g" , "http:g" ] // ; for strict parsers
151
for( check in checkAll )
154
var expect = check[1];
155
var result = base.transformReference( URI.parsed( rel, true ) );
156
assertEquals( expect, result.toString() );