1 | (require-extension srfi-1) |
---|
2 | (load "../uri-generic.scm") |
---|
3 | (import uri-generic) |
---|
4 | (require-extension test) |
---|
5 | |
---|
6 | ;; test cases from Python URI implementation |
---|
7 | |
---|
8 | (define path-cases |
---|
9 | '(("foo:xyz" "bar:abc" "bar:abc") |
---|
10 | ("http://example/x/y/z" "http://example/x/abc" "../abc") |
---|
11 | ("http://example2/x/y/z" "http://example/x/abc" "//example/x/abc") |
---|
12 | ("http://ex/x/y/z" "http://ex/x/r" "../r") |
---|
13 | |
---|
14 | ("http://ex/x/y" "http://ex/x/q/r" "./q/r") |
---|
15 | ("http://ex/x/y" "http://ex/x/q/r#s" "./q/r#s") |
---|
16 | ("http://ex/x/y" "http://ex/x/q/r#s/t" "./q/r#s/t") |
---|
17 | ("http://ex/x/y" "ftp://ex/x/q/r" "ftp://ex/x/q/r") |
---|
18 | ("http://ex/x/y" "http://ex/x/y" "") |
---|
19 | ("http://ex/x/y/" "http://ex/x/y/" "") |
---|
20 | ("http://ex/x/y/pdq" "http://ex/x/y/pdq" "") |
---|
21 | ("http://ex/x/y/" "http://ex/x/y/z/" "./z/") |
---|
22 | ("file:/swap/test/animal.rdf" "file:/swap/test/animal.rdf#Animal" "#Animal") |
---|
23 | ("file:/e/x/y/z" "file:/e/x/abc" "../abc") |
---|
24 | ("file:/example2/x/y/z" "file:/example/x/abc" "/example/x/abc") |
---|
25 | ("file:/ex/x/y/z" "file:/ex/x/r" "../r") |
---|
26 | ("file:/ex/x/y/z" "file:/r" "/r") |
---|
27 | ("file:/ex/x/y" "file:/ex/x/q/r" "./q/r") |
---|
28 | ("file:/ex/x/y" "file:/ex/x/q/r#s" "./q/r#s") |
---|
29 | ("file:/ex/x/y" "file:/ex/x/q/r#" "./q/r#") |
---|
30 | ("file:/ex/x/y" "file:/ex/x/q/r#s/t" "./q/r#s/t") |
---|
31 | ("file:/ex/x/y" "ftp://ex/x/q/r" "ftp://ex/x/q/r") |
---|
32 | ("file:/ex/x/y" "file:/ex/x/y" "") |
---|
33 | ("file:/ex/x/y/" "file:/ex/x/y/" "") |
---|
34 | ("file:/ex/x/y/pdq" "file:/ex/x/y/pdq" "") |
---|
35 | ("file:/ex/x/y/" "file:/ex/x/y/z/" "./z/") |
---|
36 | ("file:/devel/WWW/2000/10/swap/test/reluri-1.n3" "file://meetings.example.com/cal#m1" |
---|
37 | "//meetings.example.com/cal#m1") |
---|
38 | ("file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3" "file://meetings.example.com/cal#m1" |
---|
39 | "//meetings.example.com/cal#m1") |
---|
40 | ("file:/some/dir/foo" "file:/some/dir/#blort" "./#blort") |
---|
41 | ("file:/some/dir/foo" "file:/some/dir/#" "./#") |
---|
42 | ;; From Graham Klyne Thu 20 Feb 2003 18:08:17 +0000 |
---|
43 | ("http://example/x/y%2Fz" "http://example/x/abc" "./abc") |
---|
44 | ("http://example/x/y/z" "http://example/x%2Fabc" "/x%2Fabc") |
---|
45 | ("http://example/x/y%2Fz" "http://example/x%2Fabc" "/x%2Fabc") |
---|
46 | ("http://example/x%2Fy/z" "http://example/x%2Fy/abc" "./abc") |
---|
47 | ;; Ryan Lee |
---|
48 | ("http://example/x/abc.efg" "http://example/x/" "./") |
---|
49 | )) |
---|
50 | |
---|
51 | (define base "http://a/b/c/d;p?q") |
---|
52 | |
---|
53 | (define rfc-cases |
---|
54 | `((,base "g:h" "g:h") |
---|
55 | (,base "g" "http://a/b/c/g") |
---|
56 | (,base "./g" "http://a/b/c/g") |
---|
57 | (,base "g/" "http://a/b/c/g/") |
---|
58 | (,base "/g" "http://a/g") |
---|
59 | (,base "//g" "http://g") |
---|
60 | (,base "?y" "http://a/b/c/?y") |
---|
61 | (,base "g?y" "http://a/b/c/g?y") |
---|
62 | (,base "#s" "http://a/b/c/d;p?q#s") |
---|
63 | (,base "g#s" "http://a/b/c/g#s") |
---|
64 | (,base "g?y#s" "http://a/b/c/g?y#s") |
---|
65 | (,base ";x" "http://a/b/c/;x") |
---|
66 | (,base "g;x" "http://a/b/c/g;x") |
---|
67 | (,base "g;x?y#s" "http://a/b/c/g;x?y#s") |
---|
68 | (,base "." "http://a/b/c/") |
---|
69 | (,base "./" "http://a/b/c/") |
---|
70 | (,base ".." "http://a/b/") |
---|
71 | (,base "../" "http://a/b/") |
---|
72 | (,base "../g" "http://a/b/g") |
---|
73 | (,base "../.." "http://a/") |
---|
74 | (,base "../../" "http://a/") |
---|
75 | (,base "../../g" "http://a/g") |
---|
76 | )) |
---|
77 | |
---|
78 | (define extra-cases |
---|
79 | `((,base "" ,base) |
---|
80 | (,base "../../../g" "http://a/g") |
---|
81 | (,base "../../../../g" "http://a/g") |
---|
82 | (,base "/./g" "http://a/g") |
---|
83 | (,base "/../g" "http://a/g") |
---|
84 | (,base "g.." "http://a/b/c/g..") |
---|
85 | (,base "..g" "http://a/b/c/..g") |
---|
86 | |
---|
87 | (,base "./../g" "http://a/b/g") |
---|
88 | (,base "./g/." "http://a/b/c/g/") |
---|
89 | (,base "g/./h" "http://a/b/c/g/h") |
---|
90 | (,base "g/../h" "http://a/b/c/h") |
---|
91 | (,base "g;x=1/./y" "http://a/b/c/g;x=1/y") |
---|
92 | (,base "g;x=1/../y" "http://a/b/c/y") |
---|
93 | |
---|
94 | (,base "g?y/./x" "http://a/b/c/g?y/./x") |
---|
95 | (,base "g?y/../x" "http://a/b/c/g?y/../x") |
---|
96 | (,base "g#s/./x" "http://a/b/c/g#s/./x") |
---|
97 | (,base "g#s/../x" "http://a/b/c/g#s/../x") |
---|
98 | |
---|
99 | ("?a=b&c=d" "" "?a=b&c=d") |
---|
100 | (,base "" "http://a/b/c/d;p?q") |
---|
101 | ("" ,base "http://a/b/c/d;p?q") |
---|
102 | (,base "http:" "http:") |
---|
103 | (,base "..%2f" "http://a/b/c/..%2f") |
---|
104 | )) |
---|
105 | |
---|
106 | (test-group "uri test" |
---|
107 | (for-each (lambda (p) |
---|
108 | (let ((ubase (uri-reference (first p))) |
---|
109 | (urabs (uri-reference (second p))) |
---|
110 | (uabs (absolute-uri (second p))) |
---|
111 | (uex (uri-reference (third p)))) |
---|
112 | (let* ((from (uri-relative-from urabs ubase)) |
---|
113 | (to (uri-relative-to from ubase))) |
---|
114 | (test (apply sprintf "~S * ~S -> ~S" p) uex from) |
---|
115 | (test (apply sprintf "~S * ~S -> ~S" p) urabs to) |
---|
116 | (if (not (uri-fragment urabs)) |
---|
117 | (test (sprintf "~S = ~S" uabs urabs) urabs uabs)) |
---|
118 | )) |
---|
119 | (for-each |
---|
120 | (lambda (s) |
---|
121 | (test (sprintf "~S = ~S" s (uri->string (uri-reference s))) |
---|
122 | s (uri->string (uri-reference s)))) |
---|
123 | p)) |
---|
124 | path-cases)) |
---|
125 | |
---|
126 | (test-group "rfc test" |
---|
127 | (for-each (lambda (p) |
---|
128 | (let ((ubase (uri-reference (first p))) |
---|
129 | (urabs (uri-reference (second p))) |
---|
130 | (uex (uri-reference (third p)))) |
---|
131 | (let* ((to (uri-relative-to urabs ubase))) |
---|
132 | (test (apply sprintf "~S * ~S -> ~S" p) uex to) |
---|
133 | )) |
---|
134 | (for-each |
---|
135 | (lambda (s) |
---|
136 | (test (sprintf "~S = ~S" s (uri->string (uri-reference s))) |
---|
137 | s (uri->string (uri-reference s)))) |
---|
138 | p)) |
---|
139 | rfc-cases)) |
---|
140 | |
---|
141 | (test-group "extra-test" |
---|
142 | (for-each (lambda (p) |
---|
143 | (let ((ubase (uri-reference (first p))) |
---|
144 | (urabs (uri-reference (second p))) |
---|
145 | (uex (uri-reference (third p)))) |
---|
146 | (let* ((to (uri-relative-to urabs ubase))) |
---|
147 | (test (apply sprintf "~S * ~S -> ~S" p) uex to) |
---|
148 | ))) |
---|
149 | extra-cases)) |
---|
150 | |
---|
151 | (define encode/decode-cases |
---|
152 | '(("foo?bar" "foo%3fbar") |
---|
153 | ("foo&bar" "foo%26bar") |
---|
154 | ("foo%20bar" "foo%2520bar"))) |
---|
155 | |
---|
156 | (test-group "uri-encode-string test" |
---|
157 | (for-each (lambda (p) |
---|
158 | (let ((expected (second p)) |
---|
159 | (encoded (uri-encode-string (first p)))) |
---|
160 | (test (sprintf "~S -> ~S" (first p) expected) expected encoded))) |
---|
161 | encode/decode-cases)) |
---|
162 | |
---|
163 | (test-group "uri-decode-string test" |
---|
164 | (for-each (lambda (p) |
---|
165 | (let ((expected (first p)) |
---|
166 | (decoded (uri-decode-string (second p)))) |
---|
167 | (test (sprintf "~S -> ~S" (second p) expected) expected decoded))) |
---|
168 | encode/decode-cases)) |
---|
169 | |
---|
170 | (define update-cases |
---|
171 | '(("/foo" (path: ("/bar")) "/bar") |
---|
172 | ("/foo" (host: "localhost") "//localhost/foo") |
---|
173 | ("http://foo" (query: ((a . "b") (c . #t) (d . "e"))) "http://foo?a=b&c&d=e") |
---|
174 | ("http://foo" (host: #f) "http:") |
---|
175 | ("http://foo" (authority: #f) "http:"))) |
---|
176 | |
---|
177 | (test-group "update-uri test" |
---|
178 | (for-each (lambda (p) |
---|
179 | (let ((expected (uri-reference (third p))) |
---|
180 | (updated (apply update-uri (uri-reference (first p)) (second p)))) |
---|
181 | (test (sprintf "~S * ~S -> ~S" (first p) (second p) (third p)) expected updated))) |
---|
182 | update-cases)) |
---|
183 | |
---|
184 | (define normalize-case-cases |
---|
185 | '(("http://exa%2fmple/FOO%2fbar" "http://exa%2Fmple/FOO%2Fbar") |
---|
186 | ("http://EXA%2fMPLE/FOO%2fbar" "http://exa%2Fmple/FOO%2Fbar") |
---|
187 | ("HTTP://example/" "http://example/") |
---|
188 | ("http://user:PASS@example/FOO%2fbar" "http://user:PASS@example/FOO%2Fbar") |
---|
189 | ("http://uS%2fer:PA%2fSS@example/FOO%2fbar" "http://uS%2Fer:PA%2FSS@example/FOO%2Fbar") |
---|
190 | ("HTTP://example/?mooH=MUMBLe%2f" "http://example/?mooH=MUMBLe%2F") |
---|
191 | ("http://example/#baR%2f" "http://example/#baR%2F"))) |
---|
192 | |
---|
193 | (test-group "normalize-case test" |
---|
194 | (for-each (lambda (p) |
---|
195 | (let ((case-normalized (uri-normalize-case (uri-reference (first p)))) |
---|
196 | (expected (second p))) |
---|
197 | (test (sprintf "~S -> ~S" (first p) (second p)) expected (uri->string case-normalized (lambda (user pass) (conc user ":" pass)))))) |
---|
198 | normalize-case-cases)) |
---|