]> Lady’s Gitweb - Sutra/blob - xsd/functions.test.js
Add all X·S·D non‐auxillary functions
[Sutra] / xsd / functions.test.js
1 // ♓️🪡 सूत्र ∷ xsd/functions.test.js
2 // ====================================================================
3 //
4 // Copyright © 2023 Lady [@ Lady’s Computer].
5 //
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/>.
9
10 import {
11 assertAlmostEquals,
12 assertEquals,
13 assertObjectMatch,
14 assertStrictEquals,
15 assertThrows,
16 describe,
17 it,
18 } from "../dev-deps.js";
19 import {
20 booleanCanonicalMap,
21 booleanLexicalMap,
22 dateCanonicalMap,
23 dateLexicalMap,
24 dateTimeCanonicalMap,
25 dateTimeLexicalMap,
26 dateTimePlusDuration,
27 dayCanonicalFragmentMap,
28 dayFragValue,
29 daysInMonth,
30 dayTimeDurationCanonicalMap,
31 dayTimeDurationMap,
32 decimalCanonicalMap,
33 decimalLexicalMap,
34 decimalPtCanonicalMap,
35 decimalPtMap,
36 doubleCanonicalMap,
37 doubleLexicalMap,
38 durationCanonicalMap,
39 durationMap,
40 floatCanonicalMap,
41 floatLexicalMap,
42 gDayCanonicalMap,
43 gDayLexicalMap,
44 gMonthCanonicalMap,
45 gMonthDayCanonicalMap,
46 gMonthDayLexicalMap,
47 gMonthLexicalMap,
48 gYearCanonicalMap,
49 gYearLexicalMap,
50 gYearMonthCanonicalMap,
51 gYearMonthLexicalMap,
52 hexBinaryCanonical,
53 hexBinaryMap,
54 hourCanonicalFragmentMap,
55 hourFragValue,
56 minuteCanonicalFragmentMap,
57 minuteFragValue,
58 monthCanonicalFragmentMap,
59 monthFragValue,
60 newDateTime,
61 noDecimalMap,
62 noDecimalPtCanonicalMap,
63 scientificCanonicalMap,
64 scientificMap,
65 secondCanonicalFragmentMap,
66 secondFragValue,
67 specialRepCanonicalMap,
68 specialRepValue,
69 stringCanonicalMap,
70 stringLexicalMap,
71 timeCanonicalMap,
72 timeLexicalMap,
73 timeOnTimeline,
74 timezoneCanonicalFragmentMap,
75 timezoneFragValue,
76 unsignedDecimalPtCanonicalMap,
77 unsignedDecimalPtMap,
78 unsignedNoDecimalMap,
79 unsignedNoDecimalPtCanonicalMap,
80 unsignedScientificCanonicalMap,
81 yearCanonicalFragmentMap,
82 yearFragValue,
83 yearMonthDurationCanonicalMap,
84 yearMonthDurationMap,
85 } from "./functions.js";
86
87 describe("unsignedNoDecimalMap", () => {
88 it("maps the value", () => {
89 assertStrictEquals(unsignedNoDecimalMap("231"), 231);
90 });
91
92 it("throws an error if the value has a decimal point", () => {
93 assertThrows(() => {
94 unsignedNoDecimalMap("231.");
95 });
96 assertThrows(() => {
97 unsignedNoDecimalMap(".231");
98 });
99 assertThrows(() => {
100 unsignedNoDecimalMap("23.1");
101 });
102 });
103
104 it("throws an error if the value has a sign", () => {
105 assertThrows(() => {
106 unsignedNoDecimalMap("+231");
107 });
108 assertThrows(() => {
109 unsignedNoDecimalMap("-231");
110 });
111 });
112
113 it("throws an error if the value is not a string", () => {
114 assertThrows(() => {
115 unsignedNoDecimalMap(231);
116 });
117 });
118 });
119
120 describe("noDecimalMap", () => {
121 it("maps the value", () => {
122 assertStrictEquals(noDecimalMap("231"), 231);
123 assertStrictEquals(noDecimalMap("-69"), -69);
124 assertStrictEquals(noDecimalMap("+72"), +72);
125 assertStrictEquals(noDecimalMap("0"), 0);
126 assertStrictEquals(noDecimalMap("-0"), 0);
127 });
128
129 it("throws an error if the value has a decimal point", () => {
130 assertThrows(() => {
131 noDecimalMap("231.");
132 });
133 assertThrows(() => {
134 noDecimalMap(".231");
135 });
136 assertThrows(() => {
137 noDecimalMap("23.1");
138 });
139 });
140
141 it("throws an error if the value is not a string", () => {
142 assertThrows(() => {
143 noDecimalMap(231);
144 });
145 });
146 });
147
148 describe("unsignedDecimalPtMap", () => {
149 it("maps the value", () => {
150 assertStrictEquals(unsignedDecimalPtMap("231."), 231);
151 assertStrictEquals(unsignedDecimalPtMap(".231"), .231);
152 assertStrictEquals(unsignedDecimalPtMap("23.1"), 23.1);
153 });
154
155 it("throws an error if the value has no decimal point", () => {
156 assertThrows(() => {
157 unsignedDecimalPtMap("231");
158 });
159 });
160
161 it("throws an error if the value has a sign", () => {
162 assertThrows(() => {
163 unsignedDecimalPtMap("+231.");
164 });
165 assertThrows(() => {
166 unsignedDecimalPtMap("-231.");
167 });
168 });
169
170 it("throws an error if the value is not a string", () => {
171 assertThrows(() => {
172 unsignedDecimalPtMap(231);
173 });
174 });
175 });
176
177 describe("decimalPtMap", () => {
178 it("maps the value", () => {
179 assertStrictEquals(decimalPtMap("231."), 231);
180 assertStrictEquals(decimalPtMap("+.231"), .231);
181 assertStrictEquals(decimalPtMap("-23.1"), -23.1);
182 assertStrictEquals(decimalPtMap("0.0"), 0);
183 assertStrictEquals(decimalPtMap("-0.0"), 0);
184 });
185
186 it("throws an error if the value has no decimal point", () => {
187 assertThrows(() => {
188 decimalPtMap("231");
189 });
190 });
191
192 it("throws an error if the value is not a string", () => {
193 assertThrows(() => {
194 decimalPtMap(231);
195 });
196 });
197 });
198
199 describe("scientificMap", () => {
200 it("maps the value", () => {
201 assertStrictEquals(scientificMap("23E1"), 230);
202 assertStrictEquals(scientificMap("+2.3E-1"), .23);
203 assertStrictEquals(scientificMap("-.23E1"), -2.3);
204 assertStrictEquals(scientificMap("0.0E0"), 0);
205 assertStrictEquals(scientificMap("-0.0E-0"), 0);
206 });
207
208 it("throws an error if the value has no E", () => {
209 assertThrows(() => {
210 scientificMap("231");
211 });
212 });
213
214 it("throws an error if the value is not a string", () => {
215 assertThrows(() => {
216 decimalPtMap(231);
217 });
218 });
219 });
220
221 describe("unsignedNoDecimalPtCanonicalMap", () => {
222 it("maps the value", () => {
223 assertStrictEquals(unsignedNoDecimalPtCanonicalMap(231), "231");
224 assertStrictEquals(
225 unsignedNoDecimalPtCanonicalMap(1e23),
226 "100000000000000000000000",
227 );
228 assertStrictEquals(unsignedNoDecimalPtCanonicalMap(0), "0");
229 assertStrictEquals(unsignedNoDecimalPtCanonicalMap(-0), "0");
230 });
231
232 it("throws an error if the value has a fractional part", () => {
233 assertThrows(() => {
234 unsignedNoDecimalPtCanonicalMap(23.1);
235 });
236 });
237
238 it("throws an error if the value is negative", () => {
239 assertThrows(() => {
240 unsignedNoDecimalPtCanonicalMap(-231);
241 });
242 });
243
244 it("throws an error if the value is not a number", () => {
245 assertThrows(() => {
246 unsignedNoDecimalPtCanonicalMap("231");
247 });
248 });
249 });
250
251 describe("noDecimalPtCanonicalMap", () => {
252 it("maps the value", () => {
253 assertStrictEquals(noDecimalPtCanonicalMap(231), "231");
254 assertStrictEquals(noDecimalPtCanonicalMap(-231), "-231");
255 assertStrictEquals(noDecimalPtCanonicalMap(0), "0");
256 assertStrictEquals(noDecimalPtCanonicalMap(-0), "0");
257 });
258
259 it("throws an error if the value has a fractional part", () => {
260 assertThrows(() => {
261 noDecimalPtCanonicalMap(23.1);
262 });
263 });
264
265 it("throws an error if the value is not a number", () => {
266 assertThrows(() => {
267 noDecimalPtCanonicalMap("231");
268 });
269 });
270 });
271
272 describe("unsignedDecimalPtCanonicalMap", () => {
273 it("maps the value", () => {
274 assertStrictEquals(unsignedDecimalPtCanonicalMap(4), "4.0");
275 assertStrictEquals(unsignedDecimalPtCanonicalMap(231), "231.0");
276 assertStrictEquals(unsignedDecimalPtCanonicalMap(23.1), "23.1");
277 assertStrictEquals(unsignedDecimalPtCanonicalMap(.24), "0.24");
278 assertStrictEquals(
279 unsignedDecimalPtCanonicalMap(10 ** 21.5),
280 "3162277660168379400000.0",
281 );
282 assertStrictEquals(unsignedDecimalPtCanonicalMap(.0085), "0.0085");
283 assertStrictEquals(
284 unsignedDecimalPtCanonicalMap(10 ** -6.5),
285 "0.0000003162277660168379",
286 );
287 assertStrictEquals(unsignedDecimalPtCanonicalMap(0), "0.0");
288 assertStrictEquals(unsignedDecimalPtCanonicalMap(-0), "0.0");
289 });
290
291 it("throws an error if the value is negative", () => {
292 assertThrows(() => {
293 unsignedDecimalPtCanonicalMap(-231);
294 });
295 });
296
297 it("throws an error if the value is not a number", () => {
298 assertThrows(() => {
299 unsignedDecimalPtCanonicalMap("231.0");
300 });
301 });
302 });
303
304 describe("decimalPtCanonicalMap", () => {
305 it("maps the value", () => {
306 assertStrictEquals(decimalPtCanonicalMap(231), "231.0");
307 assertStrictEquals(decimalPtCanonicalMap(-23.1), "-23.1");
308 assertStrictEquals(decimalPtCanonicalMap(0), "0.0");
309 assertStrictEquals(decimalPtCanonicalMap(-0), "0.0");
310 });
311
312 it("throws an error if the value is not a number", () => {
313 assertThrows(() => {
314 decimalPtCanonicalMap("231.0");
315 });
316 });
317 });
318
319 describe("unsignedScientificCanonicalMap", () => {
320 it("maps the value", () => {
321 assertStrictEquals(unsignedScientificCanonicalMap(4), "4.0E0");
322 assertStrictEquals(unsignedScientificCanonicalMap(231), "2.31E2");
323 assertStrictEquals(unsignedScientificCanonicalMap(23), "2.3E1");
324 assertStrictEquals(unsignedScientificCanonicalMap(.24), "2.4E-1");
325 assertStrictEquals(
326 unsignedScientificCanonicalMap(10 ** 21.5),
327 "3.1622776601683794E21",
328 );
329 assertStrictEquals(
330 unsignedScientificCanonicalMap(.0085),
331 "8.5E-3",
332 );
333 assertStrictEquals(
334 unsignedScientificCanonicalMap(10 ** -6.5),
335 "3.162277660168379E-7",
336 );
337 assertStrictEquals(unsignedScientificCanonicalMap(0), "0.0E0");
338 assertStrictEquals(unsignedScientificCanonicalMap(-0), "0.0E0");
339 });
340
341 it("throws an error if the value is negative", () => {
342 assertThrows(() => {
343 unsignedScientificCanonicalMap(-231);
344 });
345 });
346
347 it("throws an error if the value is not a number", () => {
348 assertThrows(() => {
349 unsignedScientificCanonicalMap("2.31E2");
350 });
351 });
352 });
353
354 describe("scientificCanonicalMap", () => {
355 it("maps the value", () => {
356 assertStrictEquals(scientificCanonicalMap(231), "2.31E2");
357 assertStrictEquals(scientificCanonicalMap(-.231), "-2.31E-1");
358 assertStrictEquals(scientificCanonicalMap(0), "0.0E0");
359 assertStrictEquals(scientificCanonicalMap(-0), "0.0E0");
360 });
361
362 it("throws an error if the value is not a number", () => {
363 assertThrows(() => {
364 scientificCanonicalMap("2.31E2");
365 });
366 });
367 });
368
369 describe("specialRepValue", () => {
370 it("maps the value", () => {
371 assertStrictEquals(specialRepValue("INF"), Infinity);
372 assertStrictEquals(specialRepValue("+INF"), Infinity);
373 assertStrictEquals(specialRepValue("-INF"), -Infinity);
374 assertStrictEquals(specialRepValue("NaN"), NaN);
375 });
376
377 it("throws an error if the value is not a special represention", () => {
378 assertThrows(() => {
379 specialRepValue("231");
380 });
381 });
382
383 it("throws an error if the value is not a string", () => {
384 assertThrows(() => {
385 specialRepValue(Infinity);
386 });
387 });
388 });
389
390 describe("specialRepCanonicalMap", () => {
391 it("maps the value", () => {
392 assertStrictEquals(specialRepCanonicalMap(Infinity), "INF");
393 assertStrictEquals(specialRepCanonicalMap(-Infinity), "-INF");
394 assertStrictEquals(specialRepCanonicalMap(NaN), "NaN");
395 });
396
397 it("throws an error if the value is not a special value", () => {
398 assertThrows(() => {
399 specialRepCanonicalMap(231);
400 });
401 });
402
403 it("throws an error if the value is not a number", () => {
404 assertThrows(() => {
405 specialRepCanonicalMap("NaN");
406 });
407 });
408 });
409
410 describe("decimalLexicalMap", () => {
411 it("maps the value", () => {
412 assertStrictEquals(decimalLexicalMap("4.0"), 4);
413 assertStrictEquals(decimalLexicalMap("-231"), -231);
414 assertStrictEquals(decimalLexicalMap("+23.1"), 23.1);
415 assertStrictEquals(decimalLexicalMap("-0.24"), -0.24);
416 assertStrictEquals(decimalLexicalMap(".008500"), 0.0085);
417 assertStrictEquals(decimalLexicalMap("0"), 0);
418 assertStrictEquals(decimalLexicalMap("-0"), 0);
419 });
420
421 it("throws an error if the value is in exponential notation", () => {
422 assertThrows(() => {
423 decimalLexicalMap("23E1");
424 });
425 });
426
427 it("throws an error if the value is not a string", () => {
428 assertThrows(() => {
429 decimalLexicalMap(231);
430 });
431 });
432 });
433
434 describe("decimalCanonicalMap", () => {
435 it("maps the value", () => {
436 assertStrictEquals(decimalCanonicalMap(4), "4");
437 assertStrictEquals(decimalCanonicalMap(-231), "-231");
438 assertStrictEquals(decimalCanonicalMap(23.1), "23.1");
439 assertStrictEquals(decimalCanonicalMap(-.24), "-0.24");
440 assertStrictEquals(
441 decimalCanonicalMap(10 ** 21.5),
442 "3162277660168379400000",
443 );
444 assertStrictEquals(decimalCanonicalMap(.0085), "0.0085");
445 assertStrictEquals(
446 decimalCanonicalMap(10 ** -6.5),
447 "0.0000003162277660168379",
448 );
449 assertStrictEquals(decimalCanonicalMap(0), "0");
450 assertStrictEquals(decimalCanonicalMap(-0), "0");
451 });
452
453 it("throws an error if the value is not a number", () => {
454 assertThrows(() => {
455 decimalCanonicalMap("231");
456 });
457 });
458 });
459
460 describe("floatLexicalMap", () => {
461 it("maps the value", () => {
462 assertStrictEquals(floatLexicalMap("4.0"), Math.fround(4));
463 assertStrictEquals(floatLexicalMap("-231"), Math.fround(-231));
464 assertStrictEquals(floatLexicalMap("+23.1"), Math.fround(23.1));
465 assertStrictEquals(floatLexicalMap("-0.24"), Math.fround(-0.24));
466 assertStrictEquals(
467 floatLexicalMap(".008500"),
468 Math.fround(0.0085),
469 );
470 assertStrictEquals(floatLexicalMap("23E1"), Math.fround(230));
471 assertStrictEquals(floatLexicalMap("4E-20"), Math.fround(4e-20));
472 assertStrictEquals(doubleLexicalMap("+0"), 0);
473 assertStrictEquals(doubleLexicalMap("-0"), -0);
474 assertStrictEquals(doubleLexicalMap("INF"), Infinity);
475 assertStrictEquals(doubleLexicalMap("+INF"), Infinity);
476 assertStrictEquals(doubleLexicalMap("-INF"), -Infinity);
477 assertStrictEquals(doubleLexicalMap("NaN"), NaN);
478 });
479
480 it("throws an error if the value is not a string", () => {
481 assertThrows(() => {
482 floatLexicalMap(231);
483 });
484 });
485 });
486
487 describe("doubleLexicalMap", () => {
488 it("maps the value", () => {
489 assertStrictEquals(doubleLexicalMap("4.0"), 4);
490 assertStrictEquals(doubleLexicalMap("-231"), -231);
491 assertStrictEquals(doubleLexicalMap("+23.1"), 23.1);
492 assertStrictEquals(doubleLexicalMap("-0.24"), -0.24);
493 assertStrictEquals(doubleLexicalMap(".008500"), 0.0085);
494 assertStrictEquals(doubleLexicalMap("23E1"), 230);
495 assertStrictEquals(doubleLexicalMap("4E-20"), 4e-20);
496 assertStrictEquals(doubleLexicalMap("+0"), 0);
497 assertStrictEquals(doubleLexicalMap("-0"), -0);
498 assertStrictEquals(doubleLexicalMap("INF"), Infinity);
499 assertStrictEquals(doubleLexicalMap("+INF"), Infinity);
500 assertStrictEquals(doubleLexicalMap("-INF"), -Infinity);
501 assertStrictEquals(doubleLexicalMap("NaN"), NaN);
502 });
503
504 it("throws an error if the value is not a string", () => {
505 assertThrows(() => {
506 doubleLexicalMap(231);
507 });
508 });
509 });
510
511 describe("floatCanonicalMap", () => {
512 it("maps the value", () => {
513 assertStrictEquals(floatCanonicalMap(4), "4.0E0");
514 assertStrictEquals(floatCanonicalMap(-231), "-2.31E2");
515 assertStrictEquals(
516 floatCanonicalMap(23.100000381469727),
517 "2.3100000381469727E1",
518 );
519 assertStrictEquals(
520 floatCanonicalMap(-0.23999999463558197),
521 "-2.3999999463558197E-1",
522 );
523 assertStrictEquals(
524 floatCanonicalMap(0.008500000461935997),
525 "8.500000461935997E-3",
526 );
527 assertStrictEquals(
528 floatCanonicalMap(3.1622776321769755e21),
529 "3.1622776321769755E21",
530 );
531 assertStrictEquals(
532 floatCanonicalMap(3.1622775509276835e-7),
533 "3.1622775509276835E-7",
534 );
535 assertStrictEquals(floatCanonicalMap(0), "0.0E0");
536 assertStrictEquals(floatCanonicalMap(-0), "-0.0E0");
537 assertStrictEquals(floatCanonicalMap(Infinity), "INF");
538 assertStrictEquals(floatCanonicalMap(-Infinity), "-INF");
539 assertStrictEquals(floatCanonicalMap(NaN), "NaN");
540 });
541
542 it("throws an error if the value is not a float", () => {
543 assertThrows(() => {
544 floatCanonicalMap(23.1);
545 });
546 });
547
548 it("throws an error if the value is not a number", () => {
549 assertThrows(() => {
550 floatCanonicalMap("231");
551 });
552 });
553 });
554
555 describe("doubleCanonicalMap", () => {
556 it("maps the value", () => {
557 assertStrictEquals(doubleCanonicalMap(4), "4.0E0");
558 assertStrictEquals(doubleCanonicalMap(-231), "-2.31E2");
559 assertStrictEquals(doubleCanonicalMap(23.1), "2.31E1");
560 assertStrictEquals(doubleCanonicalMap(-0.24), "-2.4E-1");
561 assertStrictEquals(doubleCanonicalMap(.0085), "8.5E-3");
562 assertStrictEquals(
563 doubleCanonicalMap(10 ** 21.5),
564 "3.1622776601683794E21",
565 );
566 assertStrictEquals(
567 doubleCanonicalMap(10 ** -6.5),
568 "3.162277660168379E-7",
569 );
570 assertStrictEquals(doubleCanonicalMap(0), "0.0E0");
571 assertStrictEquals(doubleCanonicalMap(-0), "-0.0E0");
572 assertStrictEquals(doubleCanonicalMap(Infinity), "INF");
573 assertStrictEquals(doubleCanonicalMap(-Infinity), "-INF");
574 assertStrictEquals(doubleCanonicalMap(NaN), "NaN");
575 });
576
577 it("throws an error if the value is not a number", () => {
578 assertThrows(() => {
579 doubleCanonicalMap("231");
580 });
581 });
582 });
583
584 describe("durationMap", () => {
585 it("maps the value", () => {
586 assertEquals(durationMap("P0Y0M0DT0H0M0.0S"), {
587 months: 0,
588 seconds: 0,
589 });
590 assertStrictEquals(durationMap("-P0Y0M0DT0H0M0.0S").months, 0);
591 assertStrictEquals(durationMap("-P0Y0M0DT0H0M0.0S").seconds, 0);
592 assertEquals(durationMap("-P1Y2M"), { months: -14, seconds: 0 });
593 assertStrictEquals(durationMap("-P1Y2M").seconds, 0);
594 assertEquals(durationMap("-P3DT5H7M11S"), {
595 months: 0,
596 seconds: -277631,
597 });
598 assertStrictEquals(durationMap("-P3DT5H7M11S").months, 0);
599 assertEquals(durationMap("-P1Y2M3DT5H7M11.13S"), {
600 months: -14,
601 seconds: -277631.13,
602 });
603 });
604
605 it("throws an error if the value is not a string", () => {
606 assertThrows(() => {
607 durationMap(0);
608 });
609 assertThrows(() => {
610 durationMap({ months: 0, seconds: 0 });
611 });
612 });
613
614 it("throws an error if the value has no fields", () => {
615 assertThrows(() => {
616 durationMap("P");
617 });
618 });
619
620 it("throws an error if the value has a T but no time", () => {
621 assertThrows(() => {
622 durationMap("P0Y0M0DT");
623 });
624 });
625 });
626
627 describe("yearMonthDurationMap", () => {
628 it("maps the value", () => {
629 assertEquals(yearMonthDurationMap("P0Y0M"), {
630 months: 0,
631 seconds: 0,
632 });
633 assertStrictEquals(yearMonthDurationMap("-P0Y0M").months, 0);
634 assertStrictEquals(yearMonthDurationMap("-P0Y0M").seconds, 0);
635 assertEquals(yearMonthDurationMap("-P1Y2M"), {
636 months: -14,
637 seconds: 0,
638 });
639 assertStrictEquals(yearMonthDurationMap("-P1Y2M").seconds, 0);
640 });
641
642 it("throws an error if the value is not a string", () => {
643 assertThrows(() => {
644 yearMonthDurationMap(0);
645 });
646 assertThrows(() => {
647 yearMonthDurationMap({ months: 0, seconds: 0 });
648 });
649 });
650
651 it("throws an error if the value has no fields", () => {
652 assertThrows(() => {
653 yearMonthDurationMap("P");
654 });
655 });
656 });
657
658 describe("dayTimeDurationMap", () => {
659 it("maps the value", () => {
660 assertEquals(dayTimeDurationMap("P0DT0H0M0.0S"), {
661 months: 0,
662 seconds: 0,
663 });
664 assertStrictEquals(dayTimeDurationMap("-P0DT0H0M0.0S").months, 0);
665 assertStrictEquals(dayTimeDurationMap("-P0DT0H0M0.0S").seconds, 0);
666 assertEquals(dayTimeDurationMap("-P3DT5H7M11.13S"), {
667 months: 0,
668 seconds: -277631.13,
669 });
670 assertStrictEquals(
671 dayTimeDurationMap("-P3DT5H7M11.13S").months,
672 0,
673 );
674 });
675
676 it("throws an error if the value is not a string", () => {
677 assertThrows(() => {
678 dayTimeDurationMap(0);
679 });
680 assertThrows(() => {
681 dayTimeDurationMap({ months: 0, seconds: 0 });
682 });
683 });
684
685 it("throws an error if the value has no fields", () => {
686 assertThrows(() => {
687 dayTimeDurationMap("P");
688 });
689 });
690
691 it("throws an error if the value has a T but no time", () => {
692 assertThrows(() => {
693 dayTimeDurationMap("P0DT");
694 });
695 });
696 });
697
698 describe("durationCanonicalMap", () => {
699 it("maps the value", () => {
700 assertStrictEquals(
701 durationCanonicalMap({ months: 0, seconds: 0 }),
702 "PT0S",
703 );
704 assertStrictEquals(
705 durationCanonicalMap({ months: -0, seconds: -0 }),
706 "PT0S",
707 );
708 assertStrictEquals(
709 durationCanonicalMap({ months: 23, seconds: 1234.5 }),
710 "P1Y11MT20M34.5S",
711 );
712 assertStrictEquals(
713 durationCanonicalMap({ months: -14, seconds: -277631 }),
714 "-P1Y2M3DT5H7M11S",
715 );
716 });
717
718 it("throws an error if the value is not a duration", () => {
719 assertThrows(() => {
720 durationCanonicalMap("PT0S");
721 });
722 assertThrows(() => {
723 durationCanonicalMap({});
724 });
725 assertThrows(() => {
726 durationCanonicalMap(0);
727 });
728 });
729
730 it("throws an error if the signs of the terms do not match", () => {
731 assertThrows(() => {
732 durationCanonicalMap({ months: 1, seconds: -1 });
733 });
734 });
735 });
736
737 describe("yearMonthDurationCanonicalMap", () => {
738 it("maps the value", () => {
739 assertStrictEquals(
740 yearMonthDurationCanonicalMap({ months: 0, seconds: 0 }),
741 "P0M",
742 );
743 assertStrictEquals(
744 yearMonthDurationCanonicalMap({ months: -0, seconds: -0 }),
745 "P0M",
746 );
747 assertStrictEquals(
748 yearMonthDurationCanonicalMap({ months: 23, seconds: 0 }),
749 "P1Y11M",
750 );
751 assertStrictEquals(
752 yearMonthDurationCanonicalMap({ months: -14, seconds: 0 }),
753 "-P1Y2M",
754 );
755 });
756
757 it("throws an error if the value is not a duration", () => {
758 assertThrows(() => {
759 yearMonthDurationCanonicalMap("P0M");
760 });
761 assertThrows(() => {
762 yearMonthDurationCanonicalMap({});
763 });
764 assertThrows(() => {
765 yearMonthDurationCanonicalMap(0);
766 });
767 });
768
769 it("throws an error if the value of seconds is not zero", () => {
770 assertThrows(() => {
771 yearMonthDurationCanonicalMap({ months: 1, seconds: 1 });
772 });
773 });
774 });
775
776 describe("dayTimeDurationCanonicalMap", () => {
777 it("maps the value", () => {
778 assertStrictEquals(
779 dayTimeDurationCanonicalMap({ months: 0, seconds: 0 }),
780 "PT0S",
781 );
782 assertStrictEquals(
783 dayTimeDurationCanonicalMap({ months: -0, seconds: -0 }),
784 "PT0S",
785 );
786 assertStrictEquals(
787 dayTimeDurationCanonicalMap({ months: 0, seconds: 1234.5 }),
788 "PT20M34.5S",
789 );
790 assertStrictEquals(
791 dayTimeDurationCanonicalMap({ months: 0, seconds: -277631 }),
792 "-P3DT5H7M11S",
793 );
794 });
795
796 it("throws an error if the value is not a duration", () => {
797 assertThrows(() => {
798 dayTimeDurationCanonicalMap("PT0S");
799 });
800 assertThrows(() => {
801 dayTimeDurationCanonicalMap({});
802 });
803 assertThrows(() => {
804 dayTimeDurationCanonicalMap(0);
805 });
806 });
807
808 it("throws an error if the value of months is not zero", () => {
809 assertThrows(() => {
810 dayTimeDurationCanonicalMap({ months: 1, seconds: 1 });
811 });
812 });
813 });
814
815 describe("daysInMonth", () => {
816 it("returns the correct value when no year is supplied", () => {
817 assertStrictEquals(daysInMonth(undefined, 1), 31);
818 assertStrictEquals(daysInMonth(undefined, 2), 28);
819 assertStrictEquals(daysInMonth(undefined, 3), 31);
820 assertStrictEquals(daysInMonth(undefined, 4), 30);
821 assertStrictEquals(daysInMonth(undefined, 5), 31);
822 assertStrictEquals(daysInMonth(undefined, 6), 30);
823 assertStrictEquals(daysInMonth(undefined, 7), 31);
824 assertStrictEquals(daysInMonth(undefined, 8), 31);
825 assertStrictEquals(daysInMonth(undefined, 9), 30);
826 assertStrictEquals(daysInMonth(undefined, 10), 31);
827 assertStrictEquals(daysInMonth(undefined, 11), 30);
828 assertStrictEquals(daysInMonth(undefined, 12), 31);
829 });
830
831 it("returns the correct value when a year is supplied", () => {
832 assertStrictEquals(daysInMonth(1972, 12), 31);
833 assertStrictEquals(daysInMonth(1972, 2), 29);
834 assertStrictEquals(daysInMonth(1970, 2), 28);
835 assertStrictEquals(daysInMonth(2000, 2), 29);
836 assertStrictEquals(daysInMonth(1000, 2), 28);
837 assertStrictEquals(daysInMonth(800, 2), 29);
838 assertStrictEquals(daysInMonth(100, 2), 28);
839 assertStrictEquals(daysInMonth(0, 2), 29);
840 });
841
842 it("throws an error if the month is not an integer between 1 and 12", () => {
843 assertThrows(() => {
844 daysInMonth(undefined, 0);
845 });
846 assertThrows(() => {
847 daysInMonth(undefined, 13);
848 });
849 assertThrows(() => {
850 daysInMonth(undefined, "1");
851 });
852 });
853
854 it("throws an error if the year is not undefined or an integer", () => {
855 assertThrows(() => {
856 daysInMonth(null, 1);
857 });
858 assertThrows(() => {
859 daysInMonth(2.31, 1);
860 });
861 assertThrows(() => {
862 daysInMonth("undefined", 1);
863 });
864 assertThrows(() => {
865 daysInMonth("1", 1);
866 });
867 });
868 });
869
870 describe("newDateTime", () => {
871 it("returns a new datetime object", () => {
872 assertEquals(newDateTime(1, 1, 1, 0, 0, 0, 0), {
873 year: 1,
874 month: 1,
875 day: 1,
876 hour: 0,
877 minute: 0,
878 second: 0,
879 timezoneOffset: 0,
880 });
881 assertEquals(newDateTime(-1, 12, 31, 23, 59, 59.99, -840), {
882 year: -1,
883 month: 12,
884 day: 31,
885 hour: 23,
886 minute: 59,
887 second: 59.99,
888 timezoneOffset: -840,
889 });
890 });
891
892 it("fills absent values with undefined", () => {
893 assertEquals(newDateTime(), {
894 year: undefined,
895 month: undefined,
896 day: undefined,
897 hour: undefined,
898 minute: undefined,
899 second: undefined,
900 timezoneOffset: undefined,
901 });
902 });
903
904 it("normalizes the date", () => {
905 assertEquals(newDateTime(1, 2, 31, 24), {
906 year: 1,
907 month: 3,
908 day: 4,
909 hour: 0,
910 minute: undefined,
911 second: undefined,
912 timezoneOffset: undefined,
913 });
914 assertEquals(newDateTime(1, undefined, 31, 24), {
915 year: 1,
916 month: undefined,
917 day: 1,
918 hour: 0,
919 minute: undefined,
920 second: undefined,
921 timezoneOffset: undefined,
922 });
923 });
924
925 it("forbids out‐of‐range values", () => {
926 assertThrows(() => {
927 newDateTime(undefined, 0);
928 });
929 assertThrows(() => {
930 newDateTime(undefined, 13);
931 });
932 assertThrows(() => {
933 newDateTime(undefined, undefined, 0);
934 });
935 assertThrows(() => {
936 newDateTime(undefined, undefined, 32);
937 });
938 assertThrows(() => {
939 newDateTime(undefined, undefined, undefined, -1);
940 });
941 assertThrows(() => {
942 newDateTime(undefined, undefined, undefined, 25);
943 });
944 assertThrows(() => {
945 newDateTime(undefined, undefined, undefined, undefined, -1);
946 });
947 assertThrows(() => {
948 newDateTime(undefined, undefined, undefined, undefined, 61);
949 });
950 assertThrows(() => {
951 newDateTime(
952 undefined,
953 undefined,
954 undefined,
955 undefined,
956 undefined,
957 -1,
958 );
959 });
960 assertThrows(() => {
961 newDateTime(
962 undefined,
963 undefined,
964 undefined,
965 undefined,
966 undefined,
967 61,
968 );
969 });
970 assertThrows(() => {
971 newDateTime(
972 undefined,
973 undefined,
974 undefined,
975 undefined,
976 undefined,
977 undefined,
978 -841,
979 );
980 });
981 assertThrows(() => {
982 newDateTime(
983 undefined,
984 undefined,
985 undefined,
986 undefined,
987 undefined,
988 undefined,
989 841,
990 );
991 });
992 });
993
994 it("forbids values of the incorrect type", () => {
995 assertThrows(() => {
996 newDateTime(1.23);
997 });
998 assertThrows(() => {
999 newDateTime("1");
1000 });
1001 assertThrows(() => {
1002 newDateTime(undefined, 1.23);
1003 });
1004 assertThrows(() => {
1005 newDateTime(undefined, "1");
1006 });
1007 assertThrows(() => {
1008 newDateTime(undefined, undefined, 1.23);
1009 });
1010 assertThrows(() => {
1011 newDateTime(undefined, undefined, "1");
1012 });
1013 assertThrows(() => {
1014 newDateTime(undefined, undefined, undefined, 1.23);
1015 });
1016 assertThrows(() => {
1017 newDateTime(undefined, undefined, undefined, "1");
1018 });
1019 assertThrows(() => {
1020 newDateTime(undefined, undefined, undefined, undefined, 1.23);
1021 });
1022 assertThrows(() => {
1023 newDateTime(undefined, undefined, undefined, undefined, "1");
1024 });
1025 assertThrows(() => {
1026 newDateTime(
1027 undefined,
1028 undefined,
1029 undefined,
1030 undefined,
1031 undefined,
1032 "1",
1033 );
1034 });
1035 assertThrows(() => {
1036 newDateTime(
1037 undefined,
1038 undefined,
1039 undefined,
1040 undefined,
1041 undefined,
1042 undefined,
1043 1.23,
1044 );
1045 });
1046 assertThrows(() => {
1047 newDateTime(
1048 undefined,
1049 undefined,
1050 undefined,
1051 undefined,
1052 undefined,
1053 undefined,
1054 "1",
1055 );
1056 });
1057 });
1058 });
1059
1060 describe("dateTimePlusDuration", () => {
1061 it("fills absent values with undefined", () => {
1062 assertEquals(dateTimePlusDuration({ months: 0, seconds: 0 }, {}), {
1063 year: undefined,
1064 month: undefined,
1065 day: undefined,
1066 hour: undefined,
1067 minute: undefined,
1068 second: undefined,
1069 timezoneOffset: undefined,
1070 });
1071 });
1072
1073 it("correctly adds the duration to the datetime", () => {
1074 // These examples are taken from the X·S·D spec.
1075 const fuzzyResult = dateTimePlusDuration({
1076 months: 15,
1077 seconds: 457803.3,
1078 }, {
1079 year: 2000,
1080 month: 1,
1081 day: 12,
1082 hour: 12,
1083 minute: 13,
1084 second: 14,
1085 timezoneOffset: 0,
1086 });
1087 assertObjectMatch(fuzzyResult, {
1088 year: 2001,
1089 month: 4,
1090 day: 17,
1091 hour: 19,
1092 minute: 23,
1093 // seconds must be matched fuzzily
1094 timezoneOffset: 0,
1095 });
1096 assertAlmostEquals(fuzzyResult.second, 17.3);
1097 assertEquals(
1098 dateTimePlusDuration({ months: -3, seconds: 0 }, {
1099 year: 2000,
1100 month: 1,
1101 }),
1102 {
1103 year: 1999,
1104 month: 10,
1105 day: undefined,
1106 hour: undefined,
1107 minute: undefined,
1108 second: undefined,
1109 timezoneOffset: undefined,
1110 },
1111 );
1112 assertEquals(
1113 dateTimePlusDuration({ months: 0, seconds: 118800 }, {
1114 year: 2000,
1115 month: 1,
1116 day: 12,
1117 }),
1118 {
1119 year: 2000,
1120 month: 1,
1121 day: 13,
1122 hour: undefined,
1123 minute: undefined,
1124 second: undefined,
1125 timezoneOffset: undefined,
1126 },
1127 );
1128 assertEquals(
1129 dateTimePlusDuration(
1130 { months: 1, seconds: 0 },
1131 dateTimePlusDuration({ months: 0, seconds: 86400 }, {
1132 year: 2000,
1133 month: 3,
1134 day: 30,
1135 }),
1136 ),
1137 {
1138 year: 2000,
1139 month: 4,
1140 day: 30,
1141 hour: undefined,
1142 minute: undefined,
1143 second: undefined,
1144 timezoneOffset: undefined,
1145 },
1146 );
1147 assertEquals(
1148 dateTimePlusDuration(
1149 { months: 0, seconds: 86400 },
1150 dateTimePlusDuration({ months: 1, seconds: 0 }, {
1151 year: 2000,
1152 month: 3,
1153 day: 30,
1154 }),
1155 ),
1156 {
1157 year: 2000,
1158 month: 5,
1159 day: 1,
1160 hour: undefined,
1161 minute: undefined,
1162 second: undefined,
1163 timezoneOffset: undefined,
1164 },
1165 );
1166 });
1167
1168 it("follows 28 February with 01 March", () => {
1169 assertEquals(
1170 dateTimePlusDuration({ months: 0, seconds: 86400 }, {
1171 month: 2,
1172 day: 28,
1173 }),
1174 {
1175 year: undefined,
1176 month: 3,
1177 day: 1,
1178 hour: undefined,
1179 minute: undefined,
1180 second: undefined,
1181 timezoneOffset: undefined,
1182 },
1183 );
1184 });
1185
1186 it("allows 29 February without a year", () => {
1187 assertEquals(
1188 dateTimePlusDuration({ months: 0, seconds: 1 }, {
1189 month: 2,
1190 day: 29,
1191 }),
1192 {
1193 year: undefined,
1194 month: 2,
1195 day: 29,
1196 hour: undefined,
1197 minute: undefined,
1198 second: undefined,
1199 timezoneOffset: undefined,
1200 },
1201 );
1202 });
1203
1204 it("follows 29 February with 01 March", () => {
1205 assertEquals(
1206 dateTimePlusDuration({ months: 0, seconds: 86400 }, {
1207 month: 2,
1208 day: 29,
1209 }),
1210 {
1211 year: undefined,
1212 month: 3,
1213 day: 1,
1214 hour: undefined,
1215 minute: undefined,
1216 second: undefined,
1217 timezoneOffset: undefined,
1218 },
1219 );
1220 });
1221
1222 it("throws if not provided with a valid duration", () => {
1223 assertThrows(() => {
1224 dateTimePlusDuration({ months: 0 }, {});
1225 });
1226 assertThrows(() => {
1227 dateTimePlusDuration({ seconds: 0 }, {});
1228 });
1229 assertThrows(() => {
1230 dateTimePlusDuration({}, {});
1231 });
1232 assertThrows(() => {
1233 dateTimePlusDuration(0, {});
1234 });
1235 assertThrows(() => {
1236 dateTimePlusDuration("PT0S", {});
1237 });
1238 });
1239
1240 it("throws if not provided with a valid date·time", () => {
1241 assertThrows(() => {
1242 dateTimePlusDuration({ months: 0, seconds: 0 }, 0);
1243 });
1244 assertThrows(() => {
1245 dateTimePlusDuration({ seconds: 0 }, "2000-01-12T12:13:14Z");
1246 });
1247 });
1248 });
1249
1250 describe("timeOnTimeline", () => {
1251 it("gets the time", () => {
1252 assertStrictEquals(
1253 timeOnTimeline({
1254 year: 1,
1255 month: 1,
1256 day: 1,
1257 hour: 0,
1258 minute: 0,
1259 second: 0,
1260 timezoneOffset: 0,
1261 }),
1262 0,
1263 );
1264 assertStrictEquals(
1265 timeOnTimeline({
1266 year: 1,
1267 month: 1,
1268 day: 1,
1269 hour: 0,
1270 minute: 0,
1271 second: 0,
1272 timezoneOffset: 840,
1273 }),
1274 -50400,
1275 );
1276 assertStrictEquals(timeOnTimeline({}), 62230204800);
1277 assertStrictEquals(timeOnTimeline({ year: 0 }), -86400);
1278 });
1279
1280 it("throws if not provided with a valid date·time", () => {
1281 assertThrows(() => {
1282 timeOnTimeline(0);
1283 });
1284 assertThrows(() => {
1285 timeOnTimeline("2000-01-12T12:13:14Z");
1286 });
1287 });
1288 });
1289
1290 describe("yearFragValue", () => {
1291 it("maps the value", () => {
1292 assertStrictEquals(yearFragValue("0001"), 1);
1293 assertStrictEquals(yearFragValue("-0000"), 0);
1294 assertStrictEquals(yearFragValue("-10000"), -10000);
1295 assertStrictEquals(yearFragValue("99999"), 99999);
1296 });
1297
1298 it("throws an error if the value is not a string", () => {
1299 assertThrows(() => {
1300 yearFragValue(1);
1301 });
1302 });
1303
1304 it("throws an error if the value is not a valid yearFrag", () => {
1305 assertThrows(() => {
1306 yearFragValue("");
1307 });
1308 assertThrows(() => {
1309 yearFragValue("1");
1310 });
1311 assertThrows(() => {
1312 yearFragValue("01000");
1313 });
1314 });
1315 });
1316
1317 describe("monthFragValue", () => {
1318 it("maps the value", () => {
1319 assertStrictEquals(monthFragValue("01"), 1);
1320 assertStrictEquals(monthFragValue("10"), 10);
1321 assertStrictEquals(monthFragValue("12"), 12);
1322 });
1323
1324 it("throws an error if the value is not a string", () => {
1325 assertThrows(() => {
1326 monthFragValue(1);
1327 });
1328 });
1329
1330 it("throws an error if the value is not a valid monthFrag", () => {
1331 assertThrows(() => {
1332 monthFragValue("");
1333 });
1334 assertThrows(() => {
1335 monthFragValue("1");
1336 });
1337 assertThrows(() => {
1338 monthFragValue("-1");
1339 });
1340 assertThrows(() => {
1341 monthFragValue("-01");
1342 });
1343 assertThrows(() => {
1344 monthFragValue("00");
1345 });
1346 assertThrows(() => {
1347 monthFragValue("13");
1348 });
1349 assertThrows(() => {
1350 monthFragValue("20");
1351 });
1352 });
1353 });
1354
1355 describe("dayFragValue", () => {
1356 it("maps the value", () => {
1357 assertStrictEquals(dayFragValue("01"), 1);
1358 assertStrictEquals(dayFragValue("10"), 10);
1359 assertStrictEquals(dayFragValue("19"), 19);
1360 assertStrictEquals(dayFragValue("20"), 20);
1361 assertStrictEquals(dayFragValue("29"), 29);
1362 assertStrictEquals(dayFragValue("30"), 30);
1363 assertStrictEquals(dayFragValue("31"), 31);
1364 });
1365
1366 it("throws an error if the value is not a string", () => {
1367 assertThrows(() => {
1368 dayFragValue(1);
1369 });
1370 });
1371
1372 it("throws an error if the value is not a valid dayFrag", () => {
1373 assertThrows(() => {
1374 dayFragValue("");
1375 });
1376 assertThrows(() => {
1377 dayFragValue("1");
1378 });
1379 assertThrows(() => {
1380 dayFragValue("-1");
1381 });
1382 assertThrows(() => {
1383 dayFragValue("-01");
1384 });
1385 assertThrows(() => {
1386 dayFragValue("00");
1387 });
1388 assertThrows(() => {
1389 dayFragValue("32");
1390 });
1391 assertThrows(() => {
1392 dayFragValue("40");
1393 });
1394 });
1395 });
1396
1397 describe("hourFragValue", () => {
1398 it("maps the value", () => {
1399 assertStrictEquals(hourFragValue("00"), 0);
1400 assertStrictEquals(hourFragValue("01"), 1);
1401 assertStrictEquals(hourFragValue("10"), 10);
1402 assertStrictEquals(hourFragValue("19"), 19);
1403 assertStrictEquals(hourFragValue("20"), 20);
1404 assertStrictEquals(hourFragValue("23"), 23);
1405 });
1406
1407 it("throws an error if the value is not a string", () => {
1408 assertThrows(() => {
1409 hourFragValue(0);
1410 });
1411 });
1412
1413 it("throws an error if the value is not a valid hourFrag", () => {
1414 assertThrows(() => {
1415 hourFragValue("");
1416 });
1417 assertThrows(() => {
1418 hourFragValue("1");
1419 });
1420 assertThrows(() => {
1421 hourFragValue("-1");
1422 });
1423 assertThrows(() => {
1424 hourFragValue("-01");
1425 });
1426 assertThrows(() => {
1427 hourFragValue("24");
1428 });
1429 assertThrows(() => {
1430 hourFragValue("30");
1431 });
1432 assertThrows(() => {
1433 hourFragValue("01.23");
1434 });
1435 });
1436 });
1437
1438 describe("minuteFragValue", () => {
1439 it("maps the value", () => {
1440 assertStrictEquals(minuteFragValue("00"), 0);
1441 assertStrictEquals(minuteFragValue("01"), 1);
1442 assertStrictEquals(minuteFragValue("10"), 10);
1443 assertStrictEquals(minuteFragValue("19"), 19);
1444 assertStrictEquals(minuteFragValue("50"), 50);
1445 assertStrictEquals(minuteFragValue("59"), 59);
1446 });
1447
1448 it("throws an error if the value is not a string", () => {
1449 assertThrows(() => {
1450 minuteFragValue(0);
1451 });
1452 });
1453
1454 it("throws an error if the value is not a valid minuteFrag", () => {
1455 assertThrows(() => {
1456 minuteFragValue("");
1457 });
1458 assertThrows(() => {
1459 minuteFragValue("1");
1460 });
1461 assertThrows(() => {
1462 minuteFragValue("-1");
1463 });
1464 assertThrows(() => {
1465 minuteFragValue("-01");
1466 });
1467 assertThrows(() => {
1468 minuteFragValue("60");
1469 });
1470 assertThrows(() => {
1471 minuteFragValue("01.23");
1472 });
1473 });
1474 });
1475
1476 describe("secondFragValue", () => {
1477 it("maps the value", () => {
1478 assertStrictEquals(secondFragValue("00"), 0);
1479 assertStrictEquals(secondFragValue("00.00000"), 0);
1480 assertStrictEquals(secondFragValue("01"), 1);
1481 assertStrictEquals(secondFragValue("10"), 10);
1482 assertStrictEquals(secondFragValue("19"), 19);
1483 assertStrictEquals(secondFragValue("50"), 50);
1484 assertStrictEquals(secondFragValue("59"), 59);
1485 assertStrictEquals(secondFragValue("59.99"), 59.99);
1486 });
1487
1488 it("throws an error if the value is not a string", () => {
1489 assertThrows(() => {
1490 secondFragValue(0);
1491 });
1492 });
1493
1494 it("throws an error if the value is not a valid secondFrag", () => {
1495 assertThrows(() => {
1496 secondFragValue("");
1497 });
1498 assertThrows(() => {
1499 secondFragValue("1");
1500 });
1501 assertThrows(() => {
1502 secondFragValue("-1");
1503 });
1504 assertThrows(() => {
1505 secondFragValue("-01");
1506 });
1507 assertThrows(() => {
1508 secondFragValue("60");
1509 });
1510 });
1511 });
1512
1513 describe("timezoneFragValue", () => {
1514 it("maps the value", () => {
1515 assertStrictEquals(timezoneFragValue("Z"), 0);
1516 assertStrictEquals(timezoneFragValue("+00:00"), 0);
1517 assertStrictEquals(timezoneFragValue("-00:00"), 0);
1518 assertStrictEquals(timezoneFragValue("+00:01"), 1);
1519 assertStrictEquals(timezoneFragValue("+00:59"), 59);
1520 assertStrictEquals(timezoneFragValue("+01:23"), 83);
1521 assertStrictEquals(timezoneFragValue("-09:23"), -563);
1522 assertStrictEquals(timezoneFragValue("-10:23"), -623);
1523 assertStrictEquals(timezoneFragValue("+13:59"), 839);
1524 assertStrictEquals(timezoneFragValue("+14:00"), 840);
1525 assertStrictEquals(timezoneFragValue("-14:00"), -840);
1526 });
1527
1528 it("throws an error if the value is not a string", () => {
1529 assertThrows(() => {
1530 timezoneFragValue(0);
1531 });
1532 });
1533
1534 it("throws an error if the value is not a valid timezoneFrag", () => {
1535 assertThrows(() => {
1536 timezoneFragValue("");
1537 });
1538 assertThrows(() => {
1539 timezoneFragValue("0");
1540 });
1541 assertThrows(() => {
1542 timezoneFragValue("+Z");
1543 });
1544 assertThrows(() => {
1545 timezoneFragValue("-Z");
1546 });
1547 assertThrows(() => {
1548 timezoneFragValue("Z+00:00");
1549 });
1550 assertThrows(() => {
1551 timezoneFragValue("00:00");
1552 });
1553 assertThrows(() => {
1554 timezoneFragValue("0000");
1555 });
1556 assertThrows(() => {
1557 timezoneFragValue("+0000");
1558 });
1559 assertThrows(() => {
1560 timezoneFragValue("840");
1561 });
1562 assertThrows(() => {
1563 timezoneFragValue("+840");
1564 });
1565 assertThrows(() => {
1566 timezoneFragValue("+-00:00");
1567 });
1568 assertThrows(() => {
1569 timezoneFragValue("-+00:00");
1570 });
1571 assertThrows(() => {
1572 timezoneFragValue("+14:01");
1573 });
1574 assertThrows(() => {
1575 timezoneFragValue("+15:00");
1576 });
1577 });
1578 });
1579
1580 describe("dateTimeLexicalMap", () => {
1581 it("maps the value", () => {
1582 assertEquals(dateTimeLexicalMap("0001-01-01T00:00:00.00Z"), {
1583 year: 1,
1584 month: 1,
1585 day: 1,
1586 hour: 0,
1587 minute: 0,
1588 second: 0,
1589 timezoneOffset: 0,
1590 });
1591 assertEquals(dateTimeLexicalMap("-0001-12-31T24:00:00Z"), {
1592 year: 0,
1593 month: 1,
1594 day: 1,
1595 hour: 0,
1596 minute: 0,
1597 second: 0,
1598 timezoneOffset: 0,
1599 });
1600 assertEquals(dateTimeLexicalMap("-0000-01-01T00:00:00-00:00"), {
1601 year: 0,
1602 month: 1,
1603 day: 1,
1604 hour: 0,
1605 minute: 0,
1606 second: 0,
1607 timezoneOffset: 0,
1608 });
1609 assertEquals(dateTimeLexicalMap("0001-01-01T00:00:00.00"), {
1610 year: 1,
1611 month: 1,
1612 day: 1,
1613 hour: 0,
1614 minute: 0,
1615 second: 0,
1616 timezoneOffset: undefined,
1617 });
1618 assertEquals(dateTimeLexicalMap("99999-12-31T23:59:59.99+14:00"), {
1619 year: 99999,
1620 month: 12,
1621 day: 31,
1622 hour: 23,
1623 minute: 59,
1624 second: 59.99,
1625 timezoneOffset: 840,
1626 });
1627 assertEquals(dateTimeLexicalMap("1972-02-29T00:00:00"), {
1628 year: 1972,
1629 month: 2,
1630 day: 29,
1631 hour: 0,
1632 minute: 0,
1633 second: 0,
1634 timezoneOffset: undefined,
1635 });
1636 });
1637
1638 it("throws an error if the value is not a string", () => {
1639 assertThrows(() => {
1640 dateTimeLexicalMap(0);
1641 });
1642 });
1643
1644 it("throws an error if the value is not a valid dateTime", () => {
1645 assertThrows(() => {
1646 dateTimeLexicalMap("");
1647 });
1648 assertThrows(() => {
1649 dateTimeLexicalMap("1");
1650 });
1651 assertThrows(() => {
1652 dateTimeLexicalMap("10-10-10T00:00:00");
1653 });
1654 assertThrows(() => {
1655 dateTimeLexicalMap("2345-67-89T01:23:45");
1656 });
1657 assertThrows(() => {
1658 dateTimeLexicalMap("01000-10-10T10:10:10");
1659 });
1660 assertThrows(() => {
1661 dateTimeLexicalMap("0001-01-01T00:00:00.00+0000");
1662 });
1663 assertThrows(() => {
1664 dateTimeLexicalMap("0001-01-01T00:00:00.00+14:01");
1665 });
1666 assertThrows(() => {
1667 dateTimeLexicalMap("1970-02-29T00:00:00.00");
1668 });
1669 });
1670 });
1671
1672 describe("timeLexicalMap", () => {
1673 it("maps the value", () => {
1674 assertEquals(timeLexicalMap("00:00:00.00Z"), {
1675 year: undefined,
1676 month: undefined,
1677 day: undefined,
1678 hour: 0,
1679 minute: 0,
1680 second: 0,
1681 timezoneOffset: 0,
1682 });
1683 assertEquals(timeLexicalMap("24:00:00Z"), {
1684 year: undefined,
1685 month: undefined,
1686 day: undefined,
1687 hour: 0,
1688 minute: 0,
1689 second: 0,
1690 timezoneOffset: 0,
1691 });
1692 assertEquals(timeLexicalMap("23:59:59.99+14:00"), {
1693 year: undefined,
1694 month: undefined,
1695 day: undefined,
1696 hour: 23,
1697 minute: 59,
1698 second: 59.99,
1699 timezoneOffset: 840,
1700 });
1701 });
1702
1703 it("throws an error if the value is not a string", () => {
1704 assertThrows(() => {
1705 timeLexicalMap(0);
1706 });
1707 });
1708
1709 it("throws an error if the value is not a valid time", () => {
1710 assertThrows(() => {
1711 timeLexicalMap("");
1712 });
1713 assertThrows(() => {
1714 timeLexicalMap("1");
1715 });
1716 assertThrows(() => {
1717 timeLexicalMap("00:00");
1718 });
1719 assertThrows(() => {
1720 timeLexicalMap("23:45:67");
1721 });
1722 assertThrows(() => {
1723 timeLexicalMap("-10:10:10");
1724 });
1725 assertThrows(() => {
1726 timeLexicalMap("00:00:00.00+0000");
1727 });
1728 assertThrows(() => {
1729 timeLexicalMap("00:00:00.00+14:01");
1730 });
1731 assertThrows(() => {
1732 timeLexicalMap("T00:00:00");
1733 });
1734 });
1735 });
1736
1737 describe("dateLexicalMap", () => {
1738 it("maps the value", () => {
1739 assertEquals(dateLexicalMap("0001-01-01Z"), {
1740 year: 1,
1741 month: 1,
1742 day: 1,
1743 hour: undefined,
1744 minute: undefined,
1745 second: undefined,
1746 timezoneOffset: 0,
1747 });
1748 assertEquals(dateLexicalMap("-0001-12-31Z"), {
1749 year: -1,
1750 month: 12,
1751 day: 31,
1752 hour: undefined,
1753 minute: undefined,
1754 second: undefined,
1755 timezoneOffset: 0,
1756 });
1757 assertEquals(dateLexicalMap("-0000-01-01-00:00"), {
1758 year: 0,
1759 month: 1,
1760 day: 1,
1761 hour: undefined,
1762 minute: undefined,
1763 second: undefined,
1764 timezoneOffset: 0,
1765 });
1766 assertEquals(dateLexicalMap("0001-01-01"), {
1767 year: 1,
1768 month: 1,
1769 day: 1,
1770 hour: undefined,
1771 minute: undefined,
1772 second: undefined,
1773 timezoneOffset: undefined,
1774 });
1775 assertEquals(dateLexicalMap("99999-12-31+14:00"), {
1776 year: 99999,
1777 month: 12,
1778 day: 31,
1779 hour: undefined,
1780 minute: undefined,
1781 second: undefined,
1782 timezoneOffset: 840,
1783 });
1784 assertEquals(dateLexicalMap("1972-02-29"), {
1785 year: 1972,
1786 month: 2,
1787 day: 29,
1788 hour: undefined,
1789 minute: undefined,
1790 second: undefined,
1791 timezoneOffset: undefined,
1792 });
1793 });
1794
1795 it("throws an error if the value is not a string", () => {
1796 assertThrows(() => {
1797 dateLexicalMap(0);
1798 });
1799 });
1800
1801 it("throws an error if the value is not a valid date", () => {
1802 assertThrows(() => {
1803 dateLexicalMap("");
1804 });
1805 assertThrows(() => {
1806 dateLexicalMap("1");
1807 });
1808 assertThrows(() => {
1809 dateLexicalMap("10-10-10");
1810 });
1811 assertThrows(() => {
1812 dateLexicalMap("2345-67-89");
1813 });
1814 assertThrows(() => {
1815 dateLexicalMap("01000-10-10");
1816 });
1817 assertThrows(() => {
1818 dateLexicalMap("0001-01-01+0000");
1819 });
1820 assertThrows(() => {
1821 dateLexicalMap("0001-01-01+14:01");
1822 });
1823 assertThrows(() => {
1824 dateLexicalMap("1970-02-29");
1825 });
1826 assertThrows(() => {
1827 dateLexicalMap("1972-02-29T00:00:00");
1828 });
1829 });
1830 });
1831
1832 describe("gYearMonthLexicalMap", () => {
1833 it("maps the value", () => {
1834 assertEquals(gYearMonthLexicalMap("0001-01Z"), {
1835 year: 1,
1836 month: 1,
1837 day: undefined,
1838 hour: undefined,
1839 minute: undefined,
1840 second: undefined,
1841 timezoneOffset: 0,
1842 });
1843 assertEquals(gYearMonthLexicalMap("-0001-12Z"), {
1844 year: -1,
1845 month: 12,
1846 day: undefined,
1847 hour: undefined,
1848 minute: undefined,
1849 second: undefined,
1850 timezoneOffset: 0,
1851 });
1852 assertEquals(gYearMonthLexicalMap("-0000-01-00:00"), {
1853 year: 0,
1854 month: 1,
1855 day: undefined,
1856 hour: undefined,
1857 minute: undefined,
1858 second: undefined,
1859 timezoneOffset: 0,
1860 });
1861 assertEquals(gYearMonthLexicalMap("0001-01"), {
1862 year: 1,
1863 month: 1,
1864 day: undefined,
1865 hour: undefined,
1866 minute: undefined,
1867 second: undefined,
1868 timezoneOffset: undefined,
1869 });
1870 assertEquals(gYearMonthLexicalMap("99999-12+14:00"), {
1871 year: 99999,
1872 month: 12,
1873 day: undefined,
1874 hour: undefined,
1875 minute: undefined,
1876 second: undefined,
1877 timezoneOffset: 840,
1878 });
1879 assertEquals(gYearMonthLexicalMap("1972-02"), {
1880 year: 1972,
1881 month: 2,
1882 day: undefined,
1883 hour: undefined,
1884 minute: undefined,
1885 second: undefined,
1886 timezoneOffset: undefined,
1887 });
1888 });
1889
1890 it("throws an error if the value is not a string", () => {
1891 assertThrows(() => {
1892 gYearMonthLexicalMap(0);
1893 });
1894 });
1895
1896 it("throws an error if the value is not a valid gYearMonth", () => {
1897 assertThrows(() => {
1898 gYearMonthLexicalMap("");
1899 });
1900 assertThrows(() => {
1901 gYearMonthLexicalMap("1");
1902 });
1903 assertThrows(() => {
1904 gYearMonthLexicalMap("10-10");
1905 });
1906 assertThrows(() => {
1907 gYearMonthLexicalMap("2345-67");
1908 });
1909 assertThrows(() => {
1910 gYearMonthLexicalMap("01000-10");
1911 });
1912 assertThrows(() => {
1913 gYearMonthLexicalMap("0001-01+0000");
1914 });
1915 assertThrows(() => {
1916 gYearMonthLexicalMap("0001-01+14:01");
1917 });
1918 assertThrows(() => {
1919 gYearMonthLexicalMap("1970-01-01");
1920 });
1921 assertThrows(() => {
1922 gYearMonthLexicalMap("1972-02T00:00:00");
1923 });
1924 });
1925 });
1926
1927 describe("gYearLexicalMap", () => {
1928 it("maps the value", () => {
1929 assertEquals(gYearLexicalMap("0001Z"), {
1930 year: 1,
1931 month: undefined,
1932 day: undefined,
1933 hour: undefined,
1934 minute: undefined,
1935 second: undefined,
1936 timezoneOffset: 0,
1937 });
1938 assertEquals(gYearLexicalMap("-0001Z"), {
1939 year: -1,
1940 month: undefined,
1941 day: undefined,
1942 hour: undefined,
1943 minute: undefined,
1944 second: undefined,
1945 timezoneOffset: 0,
1946 });
1947 assertEquals(gYearLexicalMap("-0000-00:00"), {
1948 year: 0,
1949 month: undefined,
1950 day: undefined,
1951 hour: undefined,
1952 minute: undefined,
1953 second: undefined,
1954 timezoneOffset: 0,
1955 });
1956 assertEquals(gYearLexicalMap("0001"), {
1957 year: 1,
1958 month: undefined,
1959 day: undefined,
1960 hour: undefined,
1961 minute: undefined,
1962 second: undefined,
1963 timezoneOffset: undefined,
1964 });
1965 assertEquals(gYearLexicalMap("99999+14:00"), {
1966 year: 99999,
1967 month: undefined,
1968 day: undefined,
1969 hour: undefined,
1970 minute: undefined,
1971 second: undefined,
1972 timezoneOffset: 840,
1973 });
1974 assertEquals(gYearLexicalMap("1972"), {
1975 year: 1972,
1976 month: undefined,
1977 day: undefined,
1978 hour: undefined,
1979 minute: undefined,
1980 second: undefined,
1981 timezoneOffset: undefined,
1982 });
1983 });
1984
1985 it("throws an error if the value is not a string", () => {
1986 assertThrows(() => {
1987 gYearLexicalMap(0);
1988 });
1989 });
1990
1991 it("throws an error if the value is not a valid gYear", () => {
1992 assertThrows(() => {
1993 gYearLexicalMap("");
1994 });
1995 assertThrows(() => {
1996 gYearLexicalMap("1");
1997 });
1998 assertThrows(() => {
1999 gYearLexicalMap("10");
2000 });
2001 assertThrows(() => {
2002 gYearLexicalMap("01000");
2003 });
2004 assertThrows(() => {
2005 gYearLexicalMap("0001+0000");
2006 });
2007 assertThrows(() => {
2008 gYearLexicalMap("0001+14:01");
2009 });
2010 assertThrows(() => {
2011 gYearLexicalMap("1970-01");
2012 });
2013 assertThrows(() => {
2014 gYearLexicalMap("1972T00:00:00");
2015 });
2016 });
2017 });
2018
2019 describe("gMonthDayLexicalMap", () => {
2020 it("maps the value", () => {
2021 assertEquals(gMonthDayLexicalMap("--01-01Z"), {
2022 year: undefined,
2023 month: 1,
2024 day: 1,
2025 hour: undefined,
2026 minute: undefined,
2027 second: undefined,
2028 timezoneOffset: 0,
2029 });
2030 assertEquals(gMonthDayLexicalMap("--12-31Z"), {
2031 year: undefined,
2032 month: 12,
2033 day: 31,
2034 hour: undefined,
2035 minute: undefined,
2036 second: undefined,
2037 timezoneOffset: 0,
2038 });
2039 assertEquals(gMonthDayLexicalMap("--01-01-00:00"), {
2040 year: undefined,
2041 month: 1,
2042 day: 1,
2043 hour: undefined,
2044 minute: undefined,
2045 second: undefined,
2046 timezoneOffset: 0,
2047 });
2048 assertEquals(gMonthDayLexicalMap("--01-01"), {
2049 year: undefined,
2050 month: 1,
2051 day: 1,
2052 hour: undefined,
2053 minute: undefined,
2054 second: undefined,
2055 timezoneOffset: undefined,
2056 });
2057 assertEquals(gMonthDayLexicalMap("--12-31+14:00"), {
2058 year: undefined,
2059 month: 12,
2060 day: 31,
2061 hour: undefined,
2062 minute: undefined,
2063 second: undefined,
2064 timezoneOffset: 840,
2065 });
2066 assertEquals(gMonthDayLexicalMap("--02-29"), {
2067 year: undefined,
2068 month: 2,
2069 day: 29,
2070 hour: undefined,
2071 minute: undefined,
2072 second: undefined,
2073 timezoneOffset: undefined,
2074 });
2075 });
2076
2077 it("throws an error if the value is not a string", () => {
2078 assertThrows(() => {
2079 gMonthDayLexicalMap(0);
2080 });
2081 });
2082
2083 it("throws an error if the value is not a valid gMonthDay", () => {
2084 assertThrows(() => {
2085 gMonthDayLexicalMap("");
2086 });
2087 assertThrows(() => {
2088 gMonthDayLexicalMap("1");
2089 });
2090 assertThrows(() => {
2091 gMonthDayLexicalMap("--67-89");
2092 });
2093 assertThrows(() => {
2094 gMonthDayLexicalMap("---10-10");
2095 });
2096 assertThrows(() => {
2097 gMonthDayLexicalMap("--01-01+0000");
2098 });
2099 assertThrows(() => {
2100 gMonthDayLexicalMap("--01-01+14:01");
2101 });
2102 assertThrows(() => {
2103 gMonthDayLexicalMap("--02-30");
2104 });
2105 assertThrows(() => {
2106 gMonthDayLexicalMap("1970-01-01");
2107 });
2108 assertThrows(() => {
2109 gMonthDayLexicalMap("--02-29T00:00:00");
2110 });
2111 });
2112 });
2113
2114 describe("gDayLexicalMap", () => {
2115 it("maps the value", () => {
2116 assertEquals(gDayLexicalMap("---01Z"), {
2117 year: undefined,
2118 month: undefined,
2119 day: 1,
2120 hour: undefined,
2121 minute: undefined,
2122 second: undefined,
2123 timezoneOffset: 0,
2124 });
2125 assertEquals(gDayLexicalMap("---31Z"), {
2126 year: undefined,
2127 month: undefined,
2128 day: 31,
2129 hour: undefined,
2130 minute: undefined,
2131 second: undefined,
2132 timezoneOffset: 0,
2133 });
2134 assertEquals(gDayLexicalMap("---01-00:00"), {
2135 year: undefined,
2136 month: undefined,
2137 day: 1,
2138 hour: undefined,
2139 minute: undefined,
2140 second: undefined,
2141 timezoneOffset: 0,
2142 });
2143 assertEquals(gDayLexicalMap("---01"), {
2144 year: undefined,
2145 month: undefined,
2146 day: 1,
2147 hour: undefined,
2148 minute: undefined,
2149 second: undefined,
2150 timezoneOffset: undefined,
2151 });
2152 assertEquals(gDayLexicalMap("---31+14:00"), {
2153 year: undefined,
2154 month: undefined,
2155 day: 31,
2156 hour: undefined,
2157 minute: undefined,
2158 second: undefined,
2159 timezoneOffset: 840,
2160 });
2161 });
2162
2163 it("throws an error if the value is not a string", () => {
2164 assertThrows(() => {
2165 gDayLexicalMap(0);
2166 });
2167 });
2168
2169 it("throws an error if the value is not a valid gDay", () => {
2170 assertThrows(() => {
2171 gDayLexicalMap("");
2172 });
2173 assertThrows(() => {
2174 gDayLexicalMap("1");
2175 });
2176 assertThrows(() => {
2177 gDayLexicalMap("10");
2178 });
2179 assertThrows(() => {
2180 gDayLexicalMap("---89");
2181 });
2182 assertThrows(() => {
2183 gDayLexicalMap("----10");
2184 });
2185 assertThrows(() => {
2186 gDayLexicalMap("---01+0000");
2187 });
2188 assertThrows(() => {
2189 gDayLexicalMap("---01+14:01");
2190 });
2191 assertThrows(() => {
2192 gDayLexicalMap("--01-01");
2193 });
2194 assertThrows(() => {
2195 gDayLexicalMap("1970-01-01");
2196 });
2197 assertThrows(() => {
2198 gDayLexicalMap("---29T00:00:00");
2199 });
2200 });
2201 });
2202
2203 describe("gMonthLexicalMap", () => {
2204 it("maps the value", () => {
2205 assertEquals(gMonthLexicalMap("--01Z"), {
2206 year: undefined,
2207 month: 1,
2208 day: undefined,
2209 hour: undefined,
2210 minute: undefined,
2211 second: undefined,
2212 timezoneOffset: 0,
2213 });
2214 assertEquals(gMonthLexicalMap("--12Z"), {
2215 year: undefined,
2216 month: 12,
2217 day: undefined,
2218 hour: undefined,
2219 minute: undefined,
2220 second: undefined,
2221 timezoneOffset: 0,
2222 });
2223 assertEquals(gMonthLexicalMap("--01-00:00"), {
2224 year: undefined,
2225 month: 1,
2226 day: undefined,
2227 hour: undefined,
2228 minute: undefined,
2229 second: undefined,
2230 timezoneOffset: 0,
2231 });
2232 assertEquals(gMonthLexicalMap("--01"), {
2233 year: undefined,
2234 month: 1,
2235 day: undefined,
2236 hour: undefined,
2237 minute: undefined,
2238 second: undefined,
2239 timezoneOffset: undefined,
2240 });
2241 assertEquals(gMonthLexicalMap("--12+14:00"), {
2242 year: undefined,
2243 month: 12,
2244 day: undefined,
2245 hour: undefined,
2246 minute: undefined,
2247 second: undefined,
2248 timezoneOffset: 840,
2249 });
2250 });
2251
2252 it("throws an error if the value is not a string", () => {
2253 assertThrows(() => {
2254 gMonthLexicalMap(0);
2255 });
2256 });
2257
2258 it("throws an error if the value is not a valid gMonth", () => {
2259 assertThrows(() => {
2260 gMonthLexicalMap("");
2261 });
2262 assertThrows(() => {
2263 gMonthLexicalMap("1");
2264 });
2265 assertThrows(() => {
2266 gMonthLexicalMap("01");
2267 });
2268 assertThrows(() => {
2269 gMonthLexicalMap("--67");
2270 });
2271 assertThrows(() => {
2272 gMonthLexicalMap("---10");
2273 });
2274 assertThrows(() => {
2275 gMonthLexicalMap("--01+0000");
2276 });
2277 assertThrows(() => {
2278 gMonthLexicalMap("--01+14:01");
2279 });
2280 assertThrows(() => {
2281 gMonthLexicalMap("--13");
2282 });
2283 assertThrows(() => {
2284 gMonthLexicalMap("1970-01-01");
2285 });
2286 assertThrows(() => {
2287 gMonthLexicalMap("--02T00:00:00");
2288 });
2289 });
2290 });
2291
2292 describe("yearCanonicalFragmentMap", () => {
2293 it("maps the value", () => {
2294 assertStrictEquals(yearCanonicalFragmentMap(1), "0001");
2295 assertStrictEquals(yearCanonicalFragmentMap(0), "0000");
2296 assertStrictEquals(yearCanonicalFragmentMap(-0), "0000");
2297 assertStrictEquals(yearCanonicalFragmentMap(-1), "-0001");
2298 assertStrictEquals(yearCanonicalFragmentMap(10000), "10000");
2299 assertStrictEquals(yearCanonicalFragmentMap(-10000), "-10000");
2300 });
2301
2302 it("throws an error if the value is not an integer", () => {
2303 assertThrows(() => {
2304 yearCanonicalFragmentMap("0001");
2305 });
2306 assertThrows(() => {
2307 yearCanonicalFragmentMap(1.2);
2308 });
2309 });
2310 });
2311
2312 describe("monthCanonicalFragmentMap", () => {
2313 it("maps the value", () => {
2314 assertStrictEquals(monthCanonicalFragmentMap(1), "01");
2315 assertStrictEquals(monthCanonicalFragmentMap(12), "12");
2316 });
2317
2318 it("throws an error if the value is not a positive integer less than 13", () => {
2319 assertThrows(() => {
2320 monthCanonicalFragmentMap("01");
2321 });
2322 assertThrows(() => {
2323 monthCanonicalFragmentMap(0);
2324 });
2325 assertThrows(() => {
2326 monthCanonicalFragmentMap(-1);
2327 });
2328 assertThrows(() => {
2329 monthCanonicalFragmentMap(1.2);
2330 });
2331 assertThrows(() => {
2332 monthCanonicalFragmentMap(13);
2333 });
2334 });
2335 });
2336
2337 describe("dayCanonicalFragmentMap", () => {
2338 it("maps the value", () => {
2339 assertStrictEquals(dayCanonicalFragmentMap(1), "01");
2340 assertStrictEquals(dayCanonicalFragmentMap(12), "12");
2341 assertStrictEquals(dayCanonicalFragmentMap(21), "21");
2342 assertStrictEquals(dayCanonicalFragmentMap(30), "30");
2343 assertStrictEquals(dayCanonicalFragmentMap(31), "31");
2344 });
2345
2346 it("throws an error if the value is not a positive integer less than 32", () => {
2347 assertThrows(() => {
2348 dayCanonicalFragmentMap("01");
2349 });
2350 assertThrows(() => {
2351 dayCanonicalFragmentMap(0);
2352 });
2353 assertThrows(() => {
2354 dayCanonicalFragmentMap(-1);
2355 });
2356 assertThrows(() => {
2357 dayCanonicalFragmentMap(1.2);
2358 });
2359 assertThrows(() => {
2360 dayCanonicalFragmentMap(32);
2361 });
2362 });
2363 });
2364
2365 describe("hourCanonicalFragmentMap", () => {
2366 it("maps the value", () => {
2367 assertStrictEquals(hourCanonicalFragmentMap(0), "00");
2368 assertStrictEquals(hourCanonicalFragmentMap(-0), "00");
2369 assertStrictEquals(hourCanonicalFragmentMap(1), "01");
2370 assertStrictEquals(hourCanonicalFragmentMap(12), "12");
2371 assertStrictEquals(hourCanonicalFragmentMap(21), "21");
2372 assertStrictEquals(hourCanonicalFragmentMap(23), "23");
2373 });
2374
2375 it("throws an error if the value is not a nonnegative integer less than 24", () => {
2376 assertThrows(() => {
2377 hourCanonicalFragmentMap("00");
2378 });
2379 assertThrows(() => {
2380 hourCanonicalFragmentMap(-1);
2381 });
2382 assertThrows(() => {
2383 hourCanonicalFragmentMap(1.2);
2384 });
2385 assertThrows(() => {
2386 hourCanonicalFragmentMap(24);
2387 });
2388 });
2389 });
2390
2391 describe("minuteCanonicalFragmentMap", () => {
2392 it("maps the value", () => {
2393 assertStrictEquals(minuteCanonicalFragmentMap(0), "00");
2394 assertStrictEquals(minuteCanonicalFragmentMap(-0), "00");
2395 assertStrictEquals(minuteCanonicalFragmentMap(1), "01");
2396 assertStrictEquals(minuteCanonicalFragmentMap(12), "12");
2397 assertStrictEquals(minuteCanonicalFragmentMap(21), "21");
2398 assertStrictEquals(minuteCanonicalFragmentMap(32), "32");
2399 assertStrictEquals(minuteCanonicalFragmentMap(45), "45");
2400 assertStrictEquals(minuteCanonicalFragmentMap(59), "59");
2401 });
2402
2403 it("throws an error if the value is not a nonnegative integer less than 60", () => {
2404 assertThrows(() => {
2405 minuteCanonicalFragmentMap("00");
2406 });
2407 assertThrows(() => {
2408 minuteCanonicalFragmentMap(-1);
2409 });
2410 assertThrows(() => {
2411 minuteCanonicalFragmentMap(1.2);
2412 });
2413 assertThrows(() => {
2414 minuteCanonicalFragmentMap(60);
2415 });
2416 });
2417 });
2418
2419 describe("secondCanonicalFragmentMap", () => {
2420 it("maps the value", () => {
2421 assertStrictEquals(secondCanonicalFragmentMap(0), "00");
2422 assertStrictEquals(secondCanonicalFragmentMap(-0), "00");
2423 assertStrictEquals(secondCanonicalFragmentMap(1), "01");
2424 assertStrictEquals(secondCanonicalFragmentMap(1.2), "01.2");
2425 assertStrictEquals(secondCanonicalFragmentMap(12), "12");
2426 assertStrictEquals(secondCanonicalFragmentMap(21), "21");
2427 assertStrictEquals(secondCanonicalFragmentMap(23.1), "23.1");
2428 assertStrictEquals(secondCanonicalFragmentMap(32), "32");
2429 assertStrictEquals(secondCanonicalFragmentMap(45), "45");
2430 assertStrictEquals(secondCanonicalFragmentMap(59), "59");
2431 });
2432
2433 it("throws an error if the value is not a nonnegative decimal number less than 60", () => {
2434 assertThrows(() => {
2435 secondCanonicalFragmentMap("00");
2436 });
2437 assertThrows(() => {
2438 secondCanonicalFragmentMap(-1);
2439 });
2440 assertThrows(() => {
2441 secondCanonicalFragmentMap(60);
2442 });
2443 });
2444 });
2445
2446 describe("timezoneCanonicalFragmentMap", () => {
2447 it("maps the value", () => {
2448 assertStrictEquals(timezoneCanonicalFragmentMap(0), "Z");
2449 assertStrictEquals(timezoneCanonicalFragmentMap(-0), "Z");
2450 assertStrictEquals(timezoneCanonicalFragmentMap(1), "+00:01");
2451 assertStrictEquals(timezoneCanonicalFragmentMap(-1), "-00:01");
2452 assertStrictEquals(timezoneCanonicalFragmentMap(839), "+13:59");
2453 assertStrictEquals(timezoneCanonicalFragmentMap(-839), "-13:59");
2454 assertStrictEquals(timezoneCanonicalFragmentMap(840), "+14:00");
2455 assertStrictEquals(timezoneCanonicalFragmentMap(-840), "-14:00");
2456 });
2457
2458 it("throws an error if the value is not an integer between -840 and 840 inclusive", () => {
2459 assertThrows(() => {
2460 timezoneCanonicalFragmentMap("00");
2461 });
2462 assertThrows(() => {
2463 timezoneCanonicalFragmentMap(-841);
2464 });
2465 assertThrows(() => {
2466 timezoneCanonicalFragmentMap(841);
2467 });
2468 assertThrows(() => {
2469 timezoneCanonicalFragmentMap(1.2);
2470 });
2471 });
2472 });
2473
2474 describe("dateTimeCanonicalMap", () => {
2475 it("maps the value", () => {
2476 assertEquals(
2477 dateTimeCanonicalMap({
2478 year: 1,
2479 month: 1,
2480 day: 1,
2481 hour: 0,
2482 minute: 0,
2483 second: 0,
2484 timezoneOffset: 0,
2485 }),
2486 "0001-01-01T00:00:00Z",
2487 );
2488 assertEquals(
2489 dateTimeCanonicalMap({
2490 year: 0,
2491 month: 1,
2492 day: 1,
2493 hour: 0,
2494 minute: 0,
2495 second: 0,
2496 timezoneOffset: 0,
2497 }),
2498 "0000-01-01T00:00:00Z",
2499 );
2500 assertEquals(
2501 dateTimeCanonicalMap({
2502 year: -0,
2503 month: 1,
2504 day: 1,
2505 hour: -0,
2506 minute: -0,
2507 second: -0,
2508 timezoneOffset: -0,
2509 }),
2510 "0000-01-01T00:00:00Z",
2511 );
2512 assertEquals(
2513 dateTimeCanonicalMap({
2514 year: 1,
2515 month: 1,
2516 day: 1,
2517 hour: 0,
2518 minute: 0,
2519 second: 0,
2520 timezoneOffset: undefined,
2521 }),
2522 "0001-01-01T00:00:00",
2523 );
2524 assertEquals(
2525 dateTimeCanonicalMap({
2526 year: 99999,
2527 month: 12,
2528 day: 31,
2529 hour: 23,
2530 minute: 59,
2531 second: 59.99,
2532 timezoneOffset: 840,
2533 }),
2534 "99999-12-31T23:59:59.99+14:00",
2535 );
2536 assertEquals(
2537 dateTimeCanonicalMap({
2538 year: 1972,
2539 month: 2,
2540 day: 29,
2541 hour: 0,
2542 minute: 0,
2543 second: 0,
2544 timezoneOffset: undefined,
2545 }),
2546 "1972-02-29T00:00:00",
2547 );
2548 });
2549
2550 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
2551 assertThrows(() => {
2552 dateTimeCanonicalMap(0);
2553 });
2554 assertThrows(() => {
2555 dateTimeCanonicalMap("0001-01-01T00:00:00Z");
2556 });
2557 assertThrows(() => {
2558 dateTimeCanonicalMap({
2559 year: null,
2560 month: null,
2561 day: null,
2562 hour: null,
2563 minute: null,
2564 second: null,
2565 });
2566 });
2567 });
2568
2569 it("throws an error if the value is not a complete dateTime value", () => {
2570 assertThrows(() => {
2571 dateTimeCanonicalMap({});
2572 });
2573 assertThrows(() => {
2574 dateTimeCanonicalMap({
2575 year: 1972,
2576 month: 12,
2577 day: 31,
2578 timezoneOffset: 0,
2579 });
2580 });
2581 });
2582 });
2583
2584 describe("timeCanonicalMap", () => {
2585 it("maps the value", () => {
2586 assertEquals(
2587 timeCanonicalMap({
2588 year: undefined,
2589 month: undefined,
2590 day: undefined,
2591 hour: 0,
2592 minute: 0,
2593 second: 0,
2594 timezoneOffset: 0,
2595 }),
2596 "00:00:00Z",
2597 );
2598 assertEquals(
2599 timeCanonicalMap({
2600 year: undefined,
2601 month: undefined,
2602 day: undefined,
2603 hour: -0,
2604 minute: -0,
2605 second: -0,
2606 timezoneOffset: -0,
2607 }),
2608 "00:00:00Z",
2609 );
2610 assertEquals(
2611 timeCanonicalMap({
2612 year: undefined,
2613 month: undefined,
2614 day: undefined,
2615 hour: 23,
2616 minute: 59,
2617 second: 59.99,
2618 timezoneOffset: 840,
2619 }),
2620 "23:59:59.99+14:00",
2621 );
2622 });
2623
2624 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
2625 assertThrows(() => {
2626 timeCanonicalMap(0);
2627 });
2628 assertThrows(() => {
2629 timeCanonicalMap("00:00:00Z");
2630 });
2631 assertThrows(() => {
2632 timeCanonicalMap({
2633 year: undefined,
2634 month: undefined,
2635 day: undefined,
2636 hour: null,
2637 minute: null,
2638 second: null,
2639 });
2640 });
2641 });
2642
2643 it("throws an error if the value is not a complete time value", () => {
2644 assertThrows(() => {
2645 timeCanonicalMap({});
2646 });
2647 assertThrows(() => {
2648 timeCanonicalMap({
2649 year: 1972,
2650 month: 12,
2651 day: 31,
2652 hour: 0,
2653 minute: 0,
2654 second: 0,
2655 timezoneOffset: 0,
2656 });
2657 });
2658 assertThrows(() => {
2659 timeCanonicalMap({
2660 year: undefined,
2661 month: undefined,
2662 day: undefined,
2663 hour: 0,
2664 minute: 0,
2665 second: undefined,
2666 timezoneOffset: 0,
2667 });
2668 });
2669 });
2670 });
2671
2672 describe("dateCanonicalMap", () => {
2673 it("maps the value", () => {
2674 assertEquals(
2675 dateCanonicalMap({
2676 year: 1,
2677 month: 1,
2678 day: 1,
2679 hour: undefined,
2680 minute: undefined,
2681 second: undefined,
2682 timezoneOffset: 0,
2683 }),
2684 "0001-01-01Z",
2685 );
2686 assertEquals(
2687 dateCanonicalMap({
2688 year: 0,
2689 month: 1,
2690 day: 1,
2691 hour: undefined,
2692 minute: undefined,
2693 second: undefined,
2694 timezoneOffset: 0,
2695 }),
2696 "0000-01-01Z",
2697 );
2698 assertEquals(
2699 dateCanonicalMap({
2700 year: -0,
2701 month: 1,
2702 day: 1,
2703 hour: undefined,
2704 minute: undefined,
2705 second: undefined,
2706 timezoneOffset: -0,
2707 }),
2708 "0000-01-01Z",
2709 );
2710 assertEquals(
2711 dateCanonicalMap({
2712 year: 1,
2713 month: 1,
2714 day: 1,
2715 hour: undefined,
2716 minute: undefined,
2717 second: undefined,
2718 timezoneOffset: undefined,
2719 }),
2720 "0001-01-01",
2721 );
2722 assertEquals(
2723 dateCanonicalMap({
2724 year: 99999,
2725 month: 12,
2726 day: 31,
2727 hour: undefined,
2728 minute: undefined,
2729 second: undefined,
2730 timezoneOffset: 840,
2731 }),
2732 "99999-12-31+14:00",
2733 );
2734 assertEquals(
2735 dateCanonicalMap({
2736 year: 1972,
2737 month: 2,
2738 day: 29,
2739 hour: undefined,
2740 minute: undefined,
2741 second: undefined,
2742 timezoneOffset: undefined,
2743 }),
2744 "1972-02-29",
2745 );
2746 });
2747
2748 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
2749 assertThrows(() => {
2750 dateCanonicalMap(0);
2751 });
2752 assertThrows(() => {
2753 dateCanonicalMap("0001-01-01Z");
2754 });
2755 assertThrows(() => {
2756 dateCanonicalMap({
2757 year: null,
2758 month: null,
2759 day: null,
2760 hour: undefined,
2761 minute: undefined,
2762 second: undefined,
2763 });
2764 });
2765 });
2766
2767 it("throws an error if the value is not a complete date value", () => {
2768 assertThrows(() => {
2769 dateCanonicalMap({});
2770 });
2771 assertThrows(() => {
2772 dateCanonicalMap({
2773 year: 1972,
2774 month: 12,
2775 day: 31,
2776 hour: 0,
2777 minute: 0,
2778 second: 0,
2779 timezoneOffset: 0,
2780 });
2781 });
2782 assertThrows(() => {
2783 dateCanonicalMap({ year: 1972 });
2784 });
2785 });
2786 });
2787
2788 describe("gYearMonthCanonicalMap", () => {
2789 it("maps the value", () => {
2790 assertEquals(
2791 gYearMonthCanonicalMap({
2792 year: 1,
2793 month: 1,
2794 day: undefined,
2795 hour: undefined,
2796 minute: undefined,
2797 second: undefined,
2798 timezoneOffset: 0,
2799 }),
2800 "0001-01Z",
2801 );
2802 assertEquals(
2803 gYearMonthCanonicalMap({
2804 year: 0,
2805 month: 1,
2806 day: undefined,
2807 hour: undefined,
2808 minute: undefined,
2809 second: undefined,
2810 timezoneOffset: 0,
2811 }),
2812 "0000-01Z",
2813 );
2814 assertEquals(
2815 gYearMonthCanonicalMap({
2816 year: -0,
2817 month: 1,
2818 day: undefined,
2819 hour: undefined,
2820 minute: undefined,
2821 second: undefined,
2822 timezoneOffset: -0,
2823 }),
2824 "0000-01Z",
2825 );
2826 assertEquals(
2827 gYearMonthCanonicalMap({
2828 year: 1,
2829 month: 1,
2830 day: undefined,
2831 hour: undefined,
2832 minute: undefined,
2833 second: undefined,
2834 timezoneOffset: undefined,
2835 }),
2836 "0001-01",
2837 );
2838 assertEquals(
2839 gYearMonthCanonicalMap({
2840 year: 99999,
2841 month: 12,
2842 day: undefined,
2843 hour: undefined,
2844 minute: undefined,
2845 second: undefined,
2846 timezoneOffset: 840,
2847 }),
2848 "99999-12+14:00",
2849 );
2850 assertEquals(
2851 gYearMonthCanonicalMap({
2852 year: 1972,
2853 month: 2,
2854 day: undefined,
2855 hour: undefined,
2856 minute: undefined,
2857 second: undefined,
2858 timezoneOffset: undefined,
2859 }),
2860 "1972-02",
2861 );
2862 });
2863
2864 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
2865 assertThrows(() => {
2866 gYearMonthCanonicalMap(0);
2867 });
2868 assertThrows(() => {
2869 gYearMonthCanonicalMap("0001-01Z");
2870 });
2871 assertThrows(() => {
2872 gYearMonthCanonicalMap({
2873 year: null,
2874 month: null,
2875 day: undefined,
2876 hour: undefined,
2877 minute: undefined,
2878 second: undefined,
2879 });
2880 });
2881 });
2882
2883 it("throws an error if the value is not a complete yearMonth value", () => {
2884 assertThrows(() => {
2885 gYearMonthCanonicalMap({});
2886 });
2887 assertThrows(() => {
2888 gYearMonthCanonicalMap({
2889 year: 1972,
2890 month: 12,
2891 day: 31,
2892 hour: 0,
2893 minute: 0,
2894 second: 0,
2895 timezoneOffset: 0,
2896 });
2897 });
2898 assertThrows(() => {
2899 gYearMonthCanonicalMap({ year: 1972, month: 12, day: 31 });
2900 });
2901 assertThrows(() => {
2902 gYearMonthCanonicalMap({ year: 1972 });
2903 });
2904 });
2905 });
2906
2907 describe("gYearCanonicalMap", () => {
2908 it("maps the value", () => {
2909 assertEquals(
2910 gYearCanonicalMap({
2911 year: 1,
2912 month: undefined,
2913 day: undefined,
2914 hour: undefined,
2915 minute: undefined,
2916 second: undefined,
2917 timezoneOffset: 0,
2918 }),
2919 "0001Z",
2920 );
2921 assertEquals(
2922 gYearCanonicalMap({
2923 year: 0,
2924 month: undefined,
2925 day: undefined,
2926 hour: undefined,
2927 minute: undefined,
2928 second: undefined,
2929 timezoneOffset: 0,
2930 }),
2931 "0000Z",
2932 );
2933 assertEquals(
2934 gYearCanonicalMap({
2935 year: -0,
2936 month: undefined,
2937 day: undefined,
2938 hour: undefined,
2939 minute: undefined,
2940 second: undefined,
2941 timezoneOffset: -0,
2942 }),
2943 "0000Z",
2944 );
2945 assertEquals(
2946 gYearCanonicalMap({
2947 year: 1,
2948 month: undefined,
2949 day: undefined,
2950 hour: undefined,
2951 minute: undefined,
2952 second: undefined,
2953 timezoneOffset: undefined,
2954 }),
2955 "0001",
2956 );
2957 assertEquals(
2958 gYearCanonicalMap({
2959 year: 99999,
2960 month: undefined,
2961 day: undefined,
2962 hour: undefined,
2963 minute: undefined,
2964 second: undefined,
2965 timezoneOffset: 840,
2966 }),
2967 "99999+14:00",
2968 );
2969 assertEquals(
2970 gYearCanonicalMap({
2971 year: 1972,
2972 month: undefined,
2973 day: undefined,
2974 hour: undefined,
2975 minute: undefined,
2976 second: undefined,
2977 timezoneOffset: undefined,
2978 }),
2979 "1972",
2980 );
2981 });
2982
2983 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
2984 assertThrows(() => {
2985 gYearCanonicalMap(0);
2986 });
2987 assertThrows(() => {
2988 gYearCanonicalMap("0001Z");
2989 });
2990 assertThrows(() => {
2991 gYearCanonicalMap({
2992 year: null,
2993 month: undefined,
2994 day: undefined,
2995 hour: undefined,
2996 minute: undefined,
2997 second: undefined,
2998 });
2999 });
3000 });
3001
3002 it("throws an error if the value is not a complete gYear value", () => {
3003 assertThrows(() => {
3004 gYearCanonicalMap({});
3005 });
3006 assertThrows(() => {
3007 gYearCanonicalMap({
3008 year: 1972,
3009 month: 12,
3010 day: 31,
3011 hour: 0,
3012 minute: 0,
3013 second: 0,
3014 timezoneOffset: 0,
3015 });
3016 });
3017 assertThrows(() => {
3018 gYearCanonicalMap({ year: 1972, month: 12, day: 31 });
3019 });
3020 });
3021 });
3022
3023 describe("gMonthDayCanonicalMap", () => {
3024 it("maps the value", () => {
3025 assertEquals(
3026 gMonthDayCanonicalMap({
3027 year: undefined,
3028 month: 1,
3029 day: 1,
3030 hour: undefined,
3031 minute: undefined,
3032 second: undefined,
3033 timezoneOffset: 0,
3034 }),
3035 "--01-01Z",
3036 );
3037 assertEquals(
3038 gMonthDayCanonicalMap({
3039 year: undefined,
3040 month: 1,
3041 day: 1,
3042 hour: undefined,
3043 minute: undefined,
3044 second: undefined,
3045 timezoneOffset: undefined,
3046 }),
3047 "--01-01",
3048 );
3049 assertEquals(
3050 gMonthDayCanonicalMap({
3051 year: undefined,
3052 month: 12,
3053 day: 31,
3054 hour: undefined,
3055 minute: undefined,
3056 second: undefined,
3057 timezoneOffset: 840,
3058 }),
3059 "--12-31+14:00",
3060 );
3061 assertEquals(
3062 gMonthDayCanonicalMap({
3063 year: undefined,
3064 month: 2,
3065 day: 29,
3066 hour: undefined,
3067 minute: undefined,
3068 second: undefined,
3069 timezoneOffset: undefined,
3070 }),
3071 "--02-29",
3072 );
3073 });
3074
3075 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
3076 assertThrows(() => {
3077 gMonthDayCanonicalMap(0);
3078 });
3079 assertThrows(() => {
3080 gMonthDayCanonicalMap("--01-01Z");
3081 });
3082 assertThrows(() => {
3083 gMonthDayCanonicalMap({
3084 year: undefined,
3085 month: null,
3086 day: null,
3087 hour: undefined,
3088 minute: undefined,
3089 second: undefined,
3090 });
3091 });
3092 });
3093
3094 it("throws an error if the value is not a complete gMonthDay value", () => {
3095 assertThrows(() => {
3096 gMonthDayCanonicalMap({});
3097 });
3098 assertThrows(() => {
3099 gMonthDayCanonicalMap({
3100 year: 1972,
3101 month: 12,
3102 day: 31,
3103 hour: 0,
3104 minute: 0,
3105 second: 0,
3106 timezoneOffset: 0,
3107 });
3108 });
3109 assertThrows(() => {
3110 gMonthDayCanonicalMap({ year: 1972, month: 12, day: 31 });
3111 });
3112 assertThrows(() => {
3113 gMonthDayCanonicalMap({ day: 31 });
3114 });
3115 });
3116 });
3117
3118 describe("gDayCanonicalMap", () => {
3119 it("maps the value", () => {
3120 assertEquals(
3121 gDayCanonicalMap({
3122 year: undefined,
3123 month: undefined,
3124 day: 1,
3125 hour: undefined,
3126 minute: undefined,
3127 second: undefined,
3128 timezoneOffset: 0,
3129 }),
3130 "---01Z",
3131 );
3132 assertEquals(
3133 gDayCanonicalMap({
3134 year: undefined,
3135 month: undefined,
3136 day: 1,
3137 hour: undefined,
3138 minute: undefined,
3139 second: undefined,
3140 timezoneOffset: undefined,
3141 }),
3142 "---01",
3143 );
3144 assertEquals(
3145 gDayCanonicalMap({
3146 year: undefined,
3147 month: undefined,
3148 day: 31,
3149 hour: undefined,
3150 minute: undefined,
3151 second: undefined,
3152 timezoneOffset: 840,
3153 }),
3154 "---31+14:00",
3155 );
3156 assertEquals(
3157 gDayCanonicalMap({
3158 year: undefined,
3159 month: undefined,
3160 day: 29,
3161 hour: undefined,
3162 minute: undefined,
3163 second: undefined,
3164 timezoneOffset: undefined,
3165 }),
3166 "---29",
3167 );
3168 });
3169
3170 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
3171 assertThrows(() => {
3172 gDayCanonicalMap(0);
3173 });
3174 assertThrows(() => {
3175 gDayCanonicalMap("---01Z");
3176 });
3177 assertThrows(() => {
3178 gDayCanonicalMap({
3179 year: undefined,
3180 month: undefined,
3181 day: null,
3182 hour: undefined,
3183 minute: undefined,
3184 second: undefined,
3185 });
3186 });
3187 });
3188
3189 it("throws an error if the value is not a complete gDay value", () => {
3190 assertThrows(() => {
3191 gDayCanonicalMap({});
3192 });
3193 assertThrows(() => {
3194 gDayCanonicalMap({
3195 year: 1972,
3196 month: 12,
3197 day: 31,
3198 hour: 0,
3199 minute: 0,
3200 second: 0,
3201 timezoneOffset: 0,
3202 });
3203 });
3204 assertThrows(() => {
3205 gDayCanonicalMap({ year: 1972, month: 12, day: 31 });
3206 });
3207 });
3208 });
3209
3210 describe("gMonthCanonicalMap", () => {
3211 it("maps the value", () => {
3212 assertEquals(
3213 gMonthCanonicalMap({
3214 year: undefined,
3215 month: 1,
3216 day: undefined,
3217 hour: undefined,
3218 minute: undefined,
3219 second: undefined,
3220 timezoneOffset: 0,
3221 }),
3222 "--01Z",
3223 );
3224 assertEquals(
3225 gMonthCanonicalMap({
3226 year: undefined,
3227 month: 1,
3228 day: undefined,
3229 hour: undefined,
3230 minute: undefined,
3231 second: undefined,
3232 timezoneOffset: undefined,
3233 }),
3234 "--01",
3235 );
3236 assertEquals(
3237 gMonthCanonicalMap({
3238 year: undefined,
3239 month: 12,
3240 day: undefined,
3241 hour: undefined,
3242 minute: undefined,
3243 second: undefined,
3244 timezoneOffset: 840,
3245 }),
3246 "--12+14:00",
3247 );
3248 assertEquals(
3249 gMonthCanonicalMap({
3250 year: undefined,
3251 month: 2,
3252 day: undefined,
3253 hour: undefined,
3254 minute: undefined,
3255 second: undefined,
3256 timezoneOffset: undefined,
3257 }),
3258 "--02",
3259 );
3260 });
3261
3262 it("throws an error if the value is not a date/timeSevenPropertyModel value", () => {
3263 assertThrows(() => {
3264 gMonthCanonicalMap(0);
3265 });
3266 assertThrows(() => {
3267 gMonthCanonicalMap("--01Z");
3268 });
3269 assertThrows(() => {
3270 gMonthCanonicalMap({
3271 year: undefined,
3272 month: null,
3273 day: undefined,
3274 hour: undefined,
3275 minute: undefined,
3276 second: undefined,
3277 });
3278 });
3279 });
3280
3281 it("throws an error if the value is not a complete gMonth value", () => {
3282 assertThrows(() => {
3283 gMonthCanonicalMap({});
3284 });
3285 assertThrows(() => {
3286 gMonthCanonicalMap({
3287 year: 1972,
3288 month: 12,
3289 day: 31,
3290 hour: 0,
3291 minute: 0,
3292 second: 0,
3293 timezoneOffset: 0,
3294 });
3295 });
3296 assertThrows(() => {
3297 gMonthCanonicalMap({ year: 1972, month: 12, day: 31 });
3298 });
3299 });
3300 });
3301
3302 describe("stringLexicalMap", () => {
3303 it("maps the value", () => {
3304 assertStrictEquals(stringLexicalMap(""), "");
3305 assertStrictEquals(stringLexicalMap("etaoin"), "etaoin");
3306 });
3307
3308 it("throws an error if the value is not a string", () => {
3309 assertThrows(() => {
3310 stringLexicalMap({});
3311 });
3312 assertThrows(() => {
3313 stringLexicalMap(0);
3314 });
3315 assertThrows(() => {
3316 stringLexicalMap(new String());
3317 });
3318 });
3319 });
3320
3321 describe("booleanLexicalMap", () => {
3322 it("maps the value", () => {
3323 assertStrictEquals(booleanLexicalMap("0"), false);
3324 assertStrictEquals(booleanLexicalMap("false"), false);
3325 assertStrictEquals(booleanLexicalMap("1"), true);
3326 assertStrictEquals(booleanLexicalMap("true"), true);
3327 });
3328
3329 it("throws an error if the value is not a string", () => {
3330 assertThrows(() => {
3331 booleanLexicalMap({});
3332 });
3333 assertThrows(() => {
3334 booleanLexicalMap(0);
3335 });
3336 assertThrows(() => {
3337 booleanLexicalMap(false);
3338 });
3339 });
3340 });
3341
3342 describe("stringCanonicalMap", () => {
3343 it("maps the value", () => {
3344 assertStrictEquals(stringCanonicalMap(""), "");
3345 assertStrictEquals(stringCanonicalMap("etaoin"), "etaoin");
3346 });
3347
3348 it("throws an error if the value is not a string", () => {
3349 assertThrows(() => {
3350 stringCanonicalMap({});
3351 });
3352 assertThrows(() => {
3353 stringCanonicalMap(0);
3354 });
3355 assertThrows(() => {
3356 stringCanonicalMap(new String());
3357 });
3358 });
3359 });
3360
3361 describe("booleanCanonicalMap", () => {
3362 it("maps the value", () => {
3363 assertStrictEquals(booleanCanonicalMap(false), "false");
3364 assertStrictEquals(booleanCanonicalMap(true), "true");
3365 });
3366
3367 it("throws an error if the value is not a boolean", () => {
3368 assertThrows(() => {
3369 booleanCanonicalMap({});
3370 });
3371 assertThrows(() => {
3372 booleanCanonicalMap(0);
3373 });
3374 assertThrows(() => {
3375 booleanCanonicalMap("false");
3376 });
3377 assertThrows(() => {
3378 booleanCanonicalMap(new Boolean());
3379 });
3380 });
3381 });
3382
3383 describe("hexBinaryMap", () => {
3384 it("maps the value", () => {
3385 assertEquals(
3386 new Uint8Array(hexBinaryMap("")),
3387 new Uint8Array([]),
3388 );
3389 assertEquals(
3390 new Uint8Array(hexBinaryMap("4b494249")),
3391 new Uint8Array([75, 73, 66, 73]),
3392 );
3393 assertEquals(
3394 new Uint8Array(hexBinaryMap("626173653634")),
3395 new Uint8Array([98, 97, 115, 101, 54, 52]),
3396 );
3397 assertEquals(
3398 new Uint8Array(hexBinaryMap("14FB9C03D97E")),
3399 new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9, 0x7E]),
3400 );
3401 });
3402
3403 it("throws an error if the value is not a string", () => {
3404 assertThrows(() => {
3405 hexBinaryMap({});
3406 });
3407 assertThrows(() => {
3408 hexBinaryMap(0);
3409 });
3410 assertThrows(() => {
3411 hexBinaryMap(new ArrayBuffer());
3412 });
3413 });
3414
3415 it("throws an error if the value is not a valid hexBinary", () => {
3416 assertThrows(() => {
3417 hexBinaryMap("A");
3418 });
3419 assertThrows(() => {
3420 hexBinaryMap("EG");
3421 });
3422 });
3423 });
3424
3425 describe("hexBinaryCanonical", () => {
3426 it("maps the value", () => {
3427 assertStrictEquals(
3428 hexBinaryCanonical(new ArrayBuffer()),
3429 "",
3430 );
3431 assertEquals(
3432 hexBinaryCanonical(new Uint8Array([75, 73, 66, 73]).buffer),
3433 "4B494249",
3434 );
3435 assertEquals(
3436 hexBinaryCanonical(
3437 new Uint8Array([98, 97, 115, 101, 54, 52]).buffer,
3438 ),
3439 "626173653634",
3440 );
3441 assertEquals(
3442 hexBinaryCanonical(
3443 new Uint8Array([0x14, 0xFB, 0x9C, 0x03, 0xD9, 0x7E]).buffer,
3444 ),
3445 "14FB9C03D97E",
3446 );
3447 });
3448
3449 it("throws an error if the value is not an array buffer", () => {
3450 assertThrows(() => {
3451 hexBinaryCanonical({});
3452 });
3453 assertThrows(() => {
3454 hexBinaryCanonical(0);
3455 });
3456 assertThrows(() => {
3457 hexBinaryCanonical("");
3458 });
3459 assertThrows(() => {
3460 hexBinaryCanonical(new Uint8Array([]));
3461 });
3462 });
3463 });
This page took 0.602557 seconds and 5 git commands to generate.