]>
Lady’s Gitweb - Pisces/blob - iri.test.js
51749cdbd840d2791d775b70938065d439ff80b7
1 // ♓🌟 Piscēs ∷ iri.test.js
2 // ====================================================================
4 // Copyright © 2020–2022 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
27 } from "./dev-deps.js";
30 "ftp://ftp.is.co.za/rfc/rfc1808.txt": {
32 authority
: "ftp.is.co.za",
33 path
: "/rfc/rfc1808.txt",
35 "http://www.ietf.org/rfc/rfc2396.txt": {
37 authority
: "www.ietf.org",
38 path
: "/rfc/rfc2396.txt",
40 "ldap://[2001:db8::7]/c=GB?objectClass?one": {
42 authority
: "[2001:db8::7]",
44 query
: "objectClass?one",
46 "mailto:John.Doe@example.com": {
48 path
: "John.Doe@example.com",
50 "news:comp.infosystems.www.servers.unix": {
52 path
: "comp.infosystems.www.servers.unix",
54 "tel:+1-816-555-1212": {
56 path
: "+1-816-555-1212",
58 "telnet://192.0.2.16:80/": {
60 authority
: "192.0.2.16:80",
63 "urn:oasis:names:specification:docbook:dtd:xml:4.1.2": {
65 path
: "oasis:names:specification:docbook:dtd:xml:4.1.2",
67 "foo://example.com:8042/over/there?name=ferret#nose": {
69 authority
: "example.com:8042",
76 const exampleURIReferences
= {
85 "http://ヒキワリ.ナットウ.ニホン": {
87 authority
: "ヒキワリ.ナットウ.ニホン",
90 "http://JP納豆.例.jp/dir1/引き割り.html": {
92 authority
: "JP納豆.例.jp",
93 path
: "/dir1/引き割り.html",
97 const exampleIRIReferences
= {
98 ...exampleURIReferences
,
103 name
: "Identifies U·R·Is.",
105 for (const uri
of Object
.keys(exampleURIs
)) {
112 name
: "Identifies absolute U·R·Is.",
114 for (const [uri
, { fragment
}] of Object
.entries(exampleURIs
)) {
115 assertStrictEquals(isAbsoluteURI(uri
), fragment
== null);
121 name
: "Identifies U·R·I references.",
123 for (const uri
of Object
.keys(exampleURIReferences
)) {
124 assert(isURIReference(uri
));
130 name
: "Identifies I·R·Is.",
132 for (const iri
of Object
.keys(exampleIRIs
)) {
139 name
: "Identifies absolute I·R·Is.",
141 for (const [iri
, { fragment
}] of Object
.entries(exampleIRIs
)) {
142 assertStrictEquals(isAbsoluteIRI(iri
), fragment
== null);
148 name
: "Identifies I·R·I references.",
150 for (const iri
of Object
.keys(exampleIRIReferences
)) {
151 assert(isIRIReference(iri
));
157 name
: "Correctly parses references.",
159 for (const [iri
, value
] of Object
.entries(exampleIRIReferences
)) {
160 assertEquals(parseReference(iri
), {
162 authority
: undefined,
173 name
: "Correctly composes references.",
175 for (const [iri
, value
] of Object
.entries(exampleIRIReferences
)) {
176 assertStrictEquals(composeReference(value
), iri
);
182 name
: "Converts IRIs to URIs.",
185 iri2uri("/dir1/引き割り.html"),
186 "/dir1/%E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A.html",
192 name
: "Correctly removes dot segments.",
194 assertStrictEquals(removeDotSegments("/a/b/c/./../../g"), "/a/g");
196 removeDotSegments("mid/content=5/../6"),
203 name
: "Correctly resolves references.",
205 const base
= "http://a/b/c/d;p?q";
206 assertStrictEquals(resolveReference("g:h", base
), "g:h");
207 assertStrictEquals(resolveReference("g", base
), "http://a/b/c/g");
209 resolveReference("./g", base
),
213 resolveReference("g/", base
),
216 assertStrictEquals(resolveReference("/g", base
), "http://a/g");
217 assertStrictEquals(resolveReference("//g", base
), "http://g");
219 resolveReference("?y", base
),
220 "http://a/b/c/d;p?y",
223 resolveReference("g?y", base
),
227 resolveReference("#s", base
),
228 "http://a/b/c/d;p?q#s",
231 resolveReference("g#s", base
),
235 resolveReference("g?y#s", base
),
236 "http://a/b/c/g?y#s",
239 resolveReference(";x", base
),
243 resolveReference("g;x", base
),
247 resolveReference("g;x?y#s", base
),
248 "http://a/b/c/g;x?y#s",
251 resolveReference("", base
),
252 "http://a/b/c/d;p?q",
254 assertStrictEquals(resolveReference(".", base
), "http://a/b/c/");
255 assertStrictEquals(resolveReference("./", base
), "http://a/b/c/");
256 assertStrictEquals(resolveReference("..", base
), "http://a/b/");
257 assertStrictEquals(resolveReference("../", base
), "http://a/b/");
258 assertStrictEquals(resolveReference("../g", base
), "http://a/b/g");
259 assertStrictEquals(resolveReference("../..", base
), "http://a/");
260 assertStrictEquals(resolveReference("../../", base
), "http://a/");
262 resolveReference("../../g", base
),
266 resolveReference("../../../g", base
),
270 resolveReference("../../../../g", base
),
273 assertStrictEquals(resolveReference("/./g", base
), "http://a/g");
274 assertStrictEquals(resolveReference("/../g", base
), "http://a/g");
276 resolveReference("g.", base
),
280 resolveReference(".g", base
),
284 resolveReference("g..", base
),
288 resolveReference("..g", base
),
292 resolveReference("./../g", base
),
296 resolveReference("./g/.", base
),
300 resolveReference("g/./h", base
),
304 resolveReference("g/../h", base
),
308 resolveReference("g;x=1/./y", base
),
309 "http://a/b/c/g;x=1/y",
312 resolveReference("g;x=1/../y", base
),
316 resolveReference("g?y/./x", base
),
317 "http://a/b/c/g?y/./x",
320 resolveReference("g?y/../x", base
),
321 "http://a/b/c/g?y/../x",
324 resolveReference("g#s/./x", base
),
325 "http://a/b/c/g#s/./x",
328 resolveReference("g#s/../x", base
),
329 "http://a/b/c/g#s/../x",
331 assertStrictEquals(resolveReference("http:g", base
), "http:g");
This page took 0.127841 seconds and 3 git commands to generate.