2 # Copyright (C) 2010, Parrot Foundation.
15 % prove t/library/uri.t
20 .include 'test_more.pir'
22 load_bytecode 'URI.pir'
33 $P0 = new ['URI';'_generic']
34 $I0 = isa $P0, ['URI';'_generic']
35 ok($I0, "new ['URI';'_generic']")
36 $I0 = isa $P0, ['URI']
37 ok($I0, "isa ['URI']")
39 $P0 = new ['URI';'file']
40 $I0 = isa $P0, ['URI';'file']
41 ok($I0, "new ['URI';'file']")
42 $I0 = isa $P0, ['URI';'_generic']
43 ok($I0, "isa ['URI';'_generic']")
45 $P0 = new ['URI';'_server']
46 $I0 = isa $P0, ['URI';'_server']
47 ok($I0, "new ['URI';'_server']")
48 $I0 = isa $P0, ['URI';'_generic']
49 ok($I0, "isa ['URI';'_generic']")
51 $P0 = new ['URI';'http']
52 $I0 = isa $P0, ['URI';'http']
53 ok($I0, "new ['URI';'http']")
54 $I0 = isa $P0, ['URI';'_server']
55 ok($I0, "isa ['URI';'_server']")
57 $P0 = new ['URI';'https']
58 $I0 = isa $P0, ['URI';'https']
59 ok($I0, "new ['URI';'https']")
60 $I0 = isa $P0, ['URI';'http']
61 ok($I0, "isa ['URI';'http']")
66 factory = get_hll_global ['URI'], 'new_from_string'
68 $P0 = factory('scheme:scheme-specific-part#fragment')
69 ok($P0, "scheme:scheme-specific-part#fragment")
70 $I0 = isa $P0, ['URI';'_generic']
71 ok($I0, "isa ['URI';'_generic']")
73 is($S0, 'scheme', "scheme")
75 is($S0, 'scheme-specific-part', "opaque")
76 $S0 = $P0.'fragment'()
77 is($S0, 'fragment', "fragment")
78 $S0 = $P0.'authority'()
79 is($S0, '', "no authority")
81 is($S0, 'scheme-specific-part', "path")
82 $S0 = $P0.'path_query'()
83 is($S0, 'scheme-specific-part', "path_query")
85 $P0 = factory('scheme://authority/path?query#fragment')
86 ok($P0, "scheme://authority/path?query#fragment")
87 $I0 = isa $P0, ['URI';'_generic']
88 ok($I0, "isa ['URI';'_generic']")
90 is($S0, 'scheme', "scheme")
92 is($S0, '//authority/path?query', "opaque")
93 $S0 = $P0.'fragment'()
94 is($S0, 'fragment', "fragment")
95 $S0 = $P0.'authority'()
96 is($S0, 'authority', "authority")
98 is($S0, '/path', "path")
99 $S0 = $P0.'path_query'()
100 is($S0, '/path?query', "path_query")
102 $P0 = factory('path?query#fragment')
103 ok($P0, "path?query#fragment")
104 $I0 = isa $P0, ['URI';'_generic']
105 ok($I0, "isa ['URI';'_generic']")
107 is($S0, '', "no scheme")
109 is($S0, 'path?query', "opaque")
110 $S0 = $P0.'fragment'()
111 is($S0, 'fragment', "fragment")
112 $S0 = $P0.'authority'()
113 is($S0, '', "no authority")
115 is($S0, 'path', "path")
116 $S0 = $P0.'path_query'()
117 is($S0, 'path?query', "path_query")
122 factory = get_hll_global ['URI'], 'new_from_string'
124 $P0 = factory('file:/foo/bar')
125 ok($P0, "file:/foo/bar")
126 $I0 = isa $P0, ['URI';'file']
127 ok($I0, "isa ['URI';'file']")
129 is($S0, 'file', "scheme")
131 is($S0, '', 'no host')
133 is($S0, '/foo/bar', 'path')
138 factory = get_hll_global ['URI'], 'new_from_string'
140 $P0 = factory('http://www.parrot.org')
141 ok($P0, "http://www.parrot.org")
142 $I0 = isa $P0, ['URI';'http']
143 ok($I0, "isa ['URI';'http']")
145 is($S0, 'http', "scheme")
147 is($S0, 'www.parrot.org', 'host')
149 is($S0, '80', 'port')
151 $P0 = factory('http://127.0.0.1:8080')
152 ok($P0, "http://127.0.0.1:8080")
153 $I0 = isa $P0, ['URI';'http']
154 ok($I0, "isa ['URI';'http']")
156 is($S0, 'http', "scheme")
158 is($S0, '127.0.0.1', 'host')
160 is($S0, '8080', 'port')
162 $P0 = factory('http://user:passwd@proxy.net:8000/path')
163 ok($P0, "http://user:passwd@proxy.net:8000/path")
164 $I0 = isa $P0, ['URI';'http']
165 ok($I0, "isa ['URI';'http']")
167 is($S0, 'http', "scheme")
168 $S0 = $P0.'authority'()
169 is($S0, 'user:passwd@proxy.net:8000', 'authority')
170 $S0 = $P0.'userinfo'()
171 is($S0, 'user:passwd', 'userinfo')
173 is($S0, 'proxy.net', 'host')
175 is($S0, '8000', 'port')
180 factory = get_hll_global ['URI'], 'new_from_string'
182 $P0 = factory('https://www.parrot.org')
183 ok($P0, "https://www.parrot.org")
184 $I0 = isa $P0, ['URI';'https']
185 ok($I0, "isa ['URI';'https']")
187 is($S0, 'https', "scheme")
189 is($S0, '443', 'port')
196 # vim: expandtab shiftwidth=4 ft=pir: