]>
Lady’s Gitweb - Pisces/blob - iri.test.js
1 // ♓🌟 Piscēs ∷ iri.test.js
2 // ====================================================================
4 // Copyright © 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/>.
15 } from "./dev-deps.js";
41 const exampleURIReferences
= {
42 "ftp://ftp.is.co.za/rfc/rfc1808.txt": {
44 authority
: "ftp.is.co.za",
45 path
: "/rfc/rfc1808.txt",
47 "http://www.ietf.org/rfc/rfc2396.txt": {
49 authority
: "www.ietf.org",
50 path
: "/rfc/rfc2396.txt",
52 "ldap://[2001:db8::7]/c=GB?objectClass?one": {
54 authority
: "[2001:db8::7]",
56 query
: "objectClass?one",
58 "mailto:John.Doe@example.com": {
60 path
: "John.Doe@example.com",
62 "news:comp.infosystems.www.servers.unix": {
64 path
: "comp.infosystems.www.servers.unix",
66 "tel:+1-816-555-1212": {
68 path
: "+1-816-555-1212",
70 "telnet://192.0.2.16:80/": {
72 authority
: "192.0.2.16:80",
75 "urn:oasis:names:specification:docbook:dtd:xml:4.1.2": {
77 path
: "oasis:names:specification:docbook:dtd:xml:4.1.2",
79 "foo://example.com:8042/over/there?name=ferret#nose": {
81 authority
: "example.com:8042",
91 // If `path` is non·empty, it must contain an IRI character for tests
93 const exampleIRIReferences
= {
94 ...exampleURIReferences
,
95 "http://ヒキワリ.ナットウ.ニホン": {
97 authority
: "ヒキワリ.ナットウ.ニホン",
100 "http://JP納豆.例.jp/dir1/引き割り.html": {
102 authority
: "JP納豆.例.jp",
103 path
: "/dir1/引き割り.html",
106 path
: "/dir1/引き割り.html",
110 // If `path` is non·empty, it must contain an LEIRI character for tests
112 const exampleLEIRIReferences
= {
113 ...exampleIRIReferences
,
114 "http://example.com/ foo /": {
116 authority
: "example.com",
124 // These will not parse, so the parse result must be empty.
125 const exampleReferences
= {
126 ...exampleLEIRIReferences
,
132 describe("composeReference", () => {
133 it("[[Call]] correctly composes references", () => {
135 const [iri
, value
] of Object
.entries(exampleLEIRIReferences
)
137 assertStrictEquals(composeReference(value
), iri
);
142 describe("escapeForIRI", () => {
143 it("[[Call]] converts L·E·I·R·Is to I·R·Is", () => {
145 escapeForIRI(" æ\0"),
149 escapeForIRI("\u{F0000}?\u{F0000}#\u{F0000}"),
150 "%F3%B0%80%80?\u{F0000}#%F3%B0%80%80",
155 describe("escapeForURI", () => {
156 it("[[Call]] converts L·E·I·R·Is to U·R·Is", () => {
158 escapeForURI("/dir1/引き割り.html"),
159 "/dir1/%E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A.html",
162 escapeForURI(" æ\0"),
166 escapeForURI("\u{F0000}?\u{F0000}#\u{F0000}"),
167 "%F3%B0%80%80?%F3%B0%80%80#%F3%B0%80%80",
172 describe("isAbsoluteIRI", () => {
173 it("[[Call]] identifies absolute I·R·Is", () => {
175 const [iri
, { scheme
, fragment
}] of Object
.entries(
181 iri
in exampleIRIReferences
&& scheme
!= null &&
189 describe("isAbsoluteLEIRI", () => {
190 it("[[Call]] identifies absolute L·E·I·R·Is", () => {
192 const [leiri
, { scheme
, fragment
}] of Object
.entries(
197 isAbsoluteLEIRI(leiri
),
198 leiri
in exampleLEIRIReferences
&& scheme
!= null &&
206 describe("isAbsoluteURI", () => {
207 it("[[Call]] identifies absolute U·R·Is", () => {
209 const [uri
, { scheme
, fragment
}] of Object
.entries(
215 uri
in exampleURIReferences
&& scheme
!= null &&
223 describe("isIRI", () => {
224 it("[[Call]] identifies I·R·Is", () => {
226 const [iri
, { scheme
}] of Object
.entries(exampleReferences
)
230 iri
in exampleIRIReferences
&& scheme
!= null,
237 describe("isIRIPath", () => {
238 it("[[Call]] identifies I·R·I paths", () => {
239 for (const [iri
, { path
}] of Object
.entries(exampleReferences
)) {
244 isIRIPath(path
?? iri
),
245 iri
in exampleIRIReferences
,
253 describe("isIRIReference", () => {
254 it("[[Call]] identifies I·R·I references", () => {
255 for (const iri
of Object
.keys(exampleReferences
)) {
258 iri
in exampleIRIReferences
,
265 describe("isIRISuffix", () => {
266 it("[[Call]] identifies I·R·I suffixes", () => {
268 const [iri
, { authority
, path
}] of Object
.entries(
276 isIRISuffix(authority
+ path
),
277 iri
in exampleIRIReferences
,
285 describe("isLEIRI", () => {
286 it("[[Call]] identifies L·E·I·R·Is", () => {
288 const [leiri
, { scheme
}] of Object
.entries(exampleReferences
)
292 leiri
in exampleLEIRIReferences
&& scheme
!= null,
299 describe("isLEIRIPath", () => {
300 it("[[Call]] identifies L·E·I·R·I paths", () => {
302 const [leiri
, { path
}] of Object
.entries(exampleReferences
)
308 isLEIRIPath(path
?? leiri
),
309 leiri
in exampleLEIRIReferences
,
317 describe("isLEIRIReference", () => {
318 it("[[Call]] identifies L·E·I·R·I references", () => {
319 for (const leiri
of Object
.keys(exampleReferences
)) {
321 isLEIRIReference(leiri
),
322 leiri
in exampleLEIRIReferences
,
329 describe("isLEIRISuffix", () => {
330 it("[[Call]] identifies L·E·I·R·I suffixes", () => {
332 const [leiri
, { authority
, path
}] of Object
.entries(
340 isLEIRISuffix(authority
+ path
),
341 leiri
in exampleLEIRIReferences
,
349 describe("isURI", () => {
350 it("[[Call]] identifies U·R·Is", () => {
352 const [uri
, { scheme
}] of Object
.entries(exampleReferences
)
356 uri
in exampleURIReferences
&& scheme
!= null,
363 describe("isURIPath", () => {
364 it("[[Call]] identifies U·R·I paths", () => {
365 for (const [uri
, { path
}] of Object
.entries(exampleReferences
)) {
370 isURIPath(path
?? uri
),
371 uri
in exampleURIReferences
,
379 describe("isURIReference", () => {
380 it("[[Call]] identifies U·R·I references", () => {
381 for (const uri
of Object
.keys(exampleReferences
)) {
384 uri
in exampleURIReferences
,
391 describe("isURISuffix", () => {
392 it("[[Call]] identifies U·R·I suffixes", () => {
394 const [uri
, { authority
, path
}] of Object
.entries(
402 isURISuffix(authority
+ path
),
403 uri
in exampleURIReferences
,
411 describe("mergePaths", () => {
412 it("[[Call]] handles the case of an empty base path", () => {
414 mergePaths("", "etaoin"),
419 it("[[Call]] handles the case of a non·empty base path", () => {
421 mergePaths("/etaoin/cmfwyp", "shrdlu"),
427 describe("parseReference", () => {
428 it("[[Call]] correctly parses references", () => {
429 for (const [iri
, value
] of Object
.entries(exampleReferences
)) {
430 assertEquals(parseReference(iri
), {
432 authority
: undefined,
442 describe("removeDotSegments", () => {
443 it("[[Call]] correctly removes dot segments", () => {
444 assertStrictEquals(removeDotSegments("/a/b/c/./../../g"), "/a/g");
446 removeDotSegments("mid/content=5/../6"),
452 describe("resolveReference", () => {
453 it("[[Call]] correctly resolves references", () => {
454 const base
= "http://a/b/c/d;p?q";
455 assertStrictEquals(resolveReference("g:h", base
), "g:h");
456 assertStrictEquals(resolveReference("g", base
), "http://a/b/c/g");
458 resolveReference("./g", base
),
462 resolveReference("g/", base
),
465 assertStrictEquals(resolveReference("/g", base
), "http://a/g");
466 assertStrictEquals(resolveReference("//g", base
), "http://g");
468 resolveReference("?y", base
),
469 "http://a/b/c/d;p?y",
472 resolveReference("g?y", base
),
476 resolveReference("#s", base
),
477 "http://a/b/c/d;p?q#s",
480 resolveReference("g#s", base
),
484 resolveReference("g?y#s", base
),
485 "http://a/b/c/g?y#s",
488 resolveReference(";x", base
),
492 resolveReference("g;x", base
),
496 resolveReference("g;x?y#s", base
),
497 "http://a/b/c/g;x?y#s",
500 resolveReference("", base
),
501 "http://a/b/c/d;p?q",
503 assertStrictEquals(resolveReference(".", base
), "http://a/b/c/");
504 assertStrictEquals(resolveReference("./", base
), "http://a/b/c/");
505 assertStrictEquals(resolveReference("..", base
), "http://a/b/");
506 assertStrictEquals(resolveReference("../", base
), "http://a/b/");
507 assertStrictEquals(resolveReference("../g", base
), "http://a/b/g");
508 assertStrictEquals(resolveReference("../..", base
), "http://a/");
509 assertStrictEquals(resolveReference("../../", base
), "http://a/");
511 resolveReference("../../g", base
),
515 resolveReference("../../../g", base
),
519 resolveReference("../../../../g", base
),
522 assertStrictEquals(resolveReference("/./g", base
), "http://a/g");
523 assertStrictEquals(resolveReference("/../g", base
), "http://a/g");
525 resolveReference("g.", base
),
529 resolveReference(".g", base
),
533 resolveReference("g..", base
),
537 resolveReference("..g", base
),
541 resolveReference("./../g", base
),
545 resolveReference("./g/.", base
),
549 resolveReference("g/./h", base
),
553 resolveReference("g/../h", base
),
557 resolveReference("g;x=1/./y", base
),
558 "http://a/b/c/g;x=1/y",
561 resolveReference("g;x=1/../y", base
),
565 resolveReference("g?y/./x", base
),
566 "http://a/b/c/g?y/./x",
569 resolveReference("g?y/../x", base
),
570 "http://a/b/c/g?y/../x",
573 resolveReference("g#s/./x", base
),
574 "http://a/b/c/g#s/./x",
577 resolveReference("g#s/../x", base
),
578 "http://a/b/c/g#s/../x",
580 assertStrictEquals(resolveReference("http:g", base
), "http:g");
This page took 0.128634 seconds and 5 git commands to generate.