]>
Lady’s Gitweb - Pisces/blob - iri.test.js
a586629ff1fbbf0bb45cabc1db6f33cf8d7cda2b
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 import { assertEquals
, assertStrictEquals
} from "./dev-deps.js";
29 const exampleURIReferences
= {
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",
79 const exampleIRIReferences
= {
80 ...exampleURIReferences
,
81 "http://ヒキワリ.ナットウ.ニホン": {
83 authority
: "ヒキワリ.ナットウ.ニホン",
86 "http://JP納豆.例.jp/dir1/引き割り.html": {
88 authority
: "JP納豆.例.jp",
89 path
: "/dir1/引き割り.html",
92 path
: "/dir1/引き割り.html",
96 const exampleLEIRIReferences
= {
97 ...exampleIRIReferences
,
98 "http://example.com/ foo /": {
100 authority
: "example.com",
108 const exampleReferences
= {
109 ...exampleLEIRIReferences
,
116 name
: "Identifies U·R·Is.",
119 const [uri
, { scheme
}] of Object
.entries(exampleReferences
)
123 uri
in exampleURIReferences
&& scheme
!= null,
130 name
: "Identifies absolute U·R·Is.",
133 const [uri
, { scheme
, fragment
}] of Object
.entries(
139 uri
in exampleURIReferences
&& scheme
!= null &&
147 name
: "Identifies U·R·I references.",
149 for (const uri
of Object
.keys(exampleReferences
)) {
152 uri
in exampleURIReferences
,
159 name
: "Identifies I·R·Is.",
162 const [iri
, { scheme
}] of Object
.entries(exampleReferences
)
166 iri
in exampleIRIReferences
&& scheme
!= null,
173 name
: "Identifies absolute I·R·Is.",
176 const [iri
, { scheme
, fragment
}] of Object
.entries(
182 iri
in exampleIRIReferences
&& scheme
!= null &&
190 name
: "Identifies I·R·I references.",
192 for (const iri
of Object
.keys(exampleReferences
)) {
195 iri
in exampleIRIReferences
,
202 name
: "Identifies L·E·I·R·Is.",
205 const [leiri
, { scheme
}] of Object
.entries(exampleReferences
)
209 leiri
in exampleLEIRIReferences
&& scheme
!= null,
216 name
: "Identifies absolute L·E·I·R·Is.",
219 const [leiri
, { scheme
, fragment
}] of Object
.entries(
224 isAbsoluteLEIRI(leiri
),
225 leiri
in exampleLEIRIReferences
&& scheme
!= null &&
233 name
: "Identifies L·E·I·R·I references.",
235 for (const leiri
of Object
.keys(exampleReferences
)) {
237 isLEIRIReference(leiri
),
238 leiri
in exampleLEIRIReferences
,
245 name
: "Correctly parses references.",
247 for (const [iri
, value
] of Object
.entries(exampleReferences
)) {
248 assertEquals(parseReference(iri
), {
250 authority
: undefined,
261 name
: "Correctly composes references.",
264 const [iri
, value
] of Object
.entries(exampleLEIRIReferences
)
266 assertStrictEquals(composeReference(value
), iri
);
272 name
: "Converts (L·E·)I·R·Is to U·R·Is.",
275 escapeForURI("/dir1/引き割り.html"),
276 "/dir1/%E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A.html",
279 escapeForURI(" æ\0"),
283 escapeForURI("\u{F0000}?\u{F0000}#\u{F0000}"),
284 "%F3%B0%80%80?%F3%B0%80%80#%F3%B0%80%80",
290 name
: "Converts L·E·I·R·Is to I·R·Is.",
293 escapeForIRI(" æ\0"),
297 escapeForIRI("\u{F0000}?\u{F0000}#\u{F0000}"),
298 "%F3%B0%80%80?\u{F0000}#%F3%B0%80%80",
304 name
: "Correctly removes dot segments.",
306 assertStrictEquals(removeDotSegments("/a/b/c/./../../g"), "/a/g");
308 removeDotSegments("mid/content=5/../6"),
315 name
: "Correctly resolves references.",
317 const base
= "http://a/b/c/d;p?q";
318 assertStrictEquals(resolveReference("g:h", base
), "g:h");
319 assertStrictEquals(resolveReference("g", base
), "http://a/b/c/g");
321 resolveReference("./g", base
),
325 resolveReference("g/", base
),
328 assertStrictEquals(resolveReference("/g", base
), "http://a/g");
329 assertStrictEquals(resolveReference("//g", base
), "http://g");
331 resolveReference("?y", base
),
332 "http://a/b/c/d;p?y",
335 resolveReference("g?y", base
),
339 resolveReference("#s", base
),
340 "http://a/b/c/d;p?q#s",
343 resolveReference("g#s", base
),
347 resolveReference("g?y#s", base
),
348 "http://a/b/c/g?y#s",
351 resolveReference(";x", base
),
355 resolveReference("g;x", base
),
359 resolveReference("g;x?y#s", base
),
360 "http://a/b/c/g;x?y#s",
363 resolveReference("", base
),
364 "http://a/b/c/d;p?q",
366 assertStrictEquals(resolveReference(".", base
), "http://a/b/c/");
367 assertStrictEquals(resolveReference("./", base
), "http://a/b/c/");
368 assertStrictEquals(resolveReference("..", base
), "http://a/b/");
369 assertStrictEquals(resolveReference("../", base
), "http://a/b/");
370 assertStrictEquals(resolveReference("../g", base
), "http://a/b/g");
371 assertStrictEquals(resolveReference("../..", base
), "http://a/");
372 assertStrictEquals(resolveReference("../../", base
), "http://a/");
374 resolveReference("../../g", base
),
378 resolveReference("../../../g", base
),
382 resolveReference("../../../../g", base
),
385 assertStrictEquals(resolveReference("/./g", base
), "http://a/g");
386 assertStrictEquals(resolveReference("/../g", base
), "http://a/g");
388 resolveReference("g.", base
),
392 resolveReference(".g", base
),
396 resolveReference("g..", base
),
400 resolveReference("..g", base
),
404 resolveReference("./../g", base
),
408 resolveReference("./g/.", base
),
412 resolveReference("g/./h", base
),
416 resolveReference("g/../h", base
),
420 resolveReference("g;x=1/./y", base
),
421 "http://a/b/c/g;x=1/y",
424 resolveReference("g;x=1/../y", base
),
428 resolveReference("g?y/./x", base
),
429 "http://a/b/c/g?y/./x",
432 resolveReference("g?y/../x", base
),
433 "http://a/b/c/g?y/../x",
436 resolveReference("g#s/./x", base
),
437 "http://a/b/c/g#s/./x",
440 resolveReference("g#s/../x", base
),
441 "http://a/b/c/g#s/../x",
443 assertStrictEquals(resolveReference("http:g", base
), "http:g");
This page took 0.080716 seconds and 3 git commands to generate.