]> Lady’s Gitweb - Pisces/blob - value.test.js
Move index string functions back into value.js
[Pisces] / value.test.js
1 // SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
2 // SPDX-License-Identifier: MPL-2.0
3 /**
4 * ⁌ β™“πŸŒŸ PiscΔ“s ∷ value.test.js
5 *
6 * Copyright Β© 2022–2023, 2025 Lady [@ Ladys Computer].
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
11 */
12
13 import {
14 assertEquals,
15 assertStrictEquals,
16 assertThrows,
17 describe,
18 it,
19 } from "./dev-deps.js";
20 import {
21 ASYNC_ITERATOR,
22 canonicalNumericIndexSting,
23 completePropertyDescriptor,
24 HAS_INSTANCE,
25 IS_CONCAT_SPREADABLE,
26 isAccessorDescriptor,
27 isArrayIndexString,
28 isDataDescriptor,
29 isFullyPopulatedDescriptor,
30 isGenericDescriptor,
31 isIntegerIndexString,
32 ITERATOR,
33 LN_10,
34 LN_2,
35 LOG10_𝑒,
36 LOG2_𝑒,
37 MATCH,
38 MATCH_ALL,
39 MAXIMUM_NUMBER,
40 MAXIMUM_SAFE_INTEGRAL_NUMBER,
41 MINIMUM_NUMBER,
42 MINIMUM_SAFE_INTEGRAL_NUMBER,
43 NAN,
44 NEGATIVE_INFINITY,
45 NEGATIVE_ZERO,
46 NULL,
47 ordinaryToPrimitive,
48 POSITIVE_INFINITY,
49 POSITIVE_ZERO,
50 RECIPROCAL_SQRT_2,
51 REPLACE,
52 sameValue,
53 sameValueZero,
54 SPECIES,
55 SPLIT,
56 SQRT_2,
57 TO_PRIMITIVE,
58 TO_STRING_TAG,
59 toFunctionName,
60 toIndex,
61 toLength,
62 toPrimitive,
63 toPropertyKey,
64 type,
65 UNDEFINED,
66 UNSCOPABLES,
67 𝑒,
68 πœ€,
69 πœ‹,
70 } from "./value.js";
71
72 describe("ASYNC_ITERATOR", () => {
73 it("[[Get]] is @@asyncIterator", () => {
74 assertStrictEquals(ASYNC_ITERATOR, Symbol.asyncIterator);
75 });
76 });
77
78 describe("HAS_INSTANCE", () => {
79 it("[[Get]] is @@hasInstance", () => {
80 assertStrictEquals(HAS_INSTANCE, Symbol.hasInstance);
81 });
82 });
83
84 describe("IS_CONCAT_SPREADABLE", () => {
85 it("[[Get]] is @@isConcatSpreadable", () => {
86 assertStrictEquals(
87 IS_CONCAT_SPREADABLE,
88 Symbol.isConcatSpreadable,
89 );
90 });
91 });
92
93 describe("ITERATOR", () => {
94 it("[[Get]] is @@iterator", () => {
95 assertStrictEquals(ITERATOR, Symbol.iterator);
96 });
97 });
98
99 describe("LN_10", () => {
100 it("[[Get]] is ln(10)", () => {
101 assertStrictEquals(LN_10, Math.LN10);
102 });
103 });
104
105 describe("LN_2", () => {
106 it("[[Get]] is ln(2)", () => {
107 assertStrictEquals(LN_2, Math.LN2);
108 });
109 });
110
111 describe("LOG10_𝑒", () => {
112 it("[[Get]] is log10(𝑒)", () => {
113 assertStrictEquals(LOG10_𝑒, Math.LOG10E);
114 });
115 });
116
117 describe("LOG2_𝑒", () => {
118 it("[[Get]] is log2(ℇ)", () => {
119 assertStrictEquals(LOG2_𝑒, Math.LOG2E);
120 });
121 });
122
123 describe("MATCH", () => {
124 it("[[Get]] is @@match", () => {
125 assertStrictEquals(MATCH, Symbol.match);
126 });
127 });
128
129 describe("MATCH_ALL", () => {
130 it("[[Get]] is @@matchAll", () => {
131 assertStrictEquals(MATCH_ALL, Symbol.matchAll);
132 });
133 });
134
135 describe("MAXIMUM_NUMBER", () => {
136 it("[[Get]] is the maximum number", () => {
137 assertStrictEquals(MAXIMUM_NUMBER, Number.MAX_VALUE);
138 });
139 });
140
141 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
142 it("[[Get]] is the maximum safe integral number", () => {
143 assertStrictEquals(
144 MAXIMUM_SAFE_INTEGRAL_NUMBER,
145 Number.MAX_SAFE_INTEGER,
146 );
147 });
148 });
149
150 describe("MINIMUM_NUMBER", () => {
151 it("[[Get]] is the minimum number", () => {
152 assertStrictEquals(MINIMUM_NUMBER, Number.MIN_VALUE);
153 });
154 });
155
156 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
157 it("[[Get]] is the minimum safe integral number", () => {
158 assertStrictEquals(
159 MINIMUM_SAFE_INTEGRAL_NUMBER,
160 Number.MIN_SAFE_INTEGER,
161 );
162 });
163 });
164
165 describe("NAN", () => {
166 it("[[Get]] is nan", () => {
167 assertStrictEquals(NAN, NaN);
168 });
169 });
170
171 describe("NEGATIVE_INFINITY", () => {
172 it("[[Get]] is negative infinity", () => {
173 assertStrictEquals(NEGATIVE_INFINITY, -Infinity);
174 });
175 });
176
177 describe("NEGATIVE_ZERO", () => {
178 it("[[Get]] is negative zero", () => {
179 assertStrictEquals(NEGATIVE_ZERO, -0);
180 });
181 });
182
183 describe("NULL", () => {
184 it("[[Get]] is null", () => {
185 assertStrictEquals(NULL, null);
186 });
187 });
188
189 describe("POSITIVE_INFINITY", () => {
190 it("[[Get]] is negative infinity", () => {
191 assertStrictEquals(POSITIVE_INFINITY, Infinity);
192 });
193 });
194
195 describe("POSITIVE_ZERO", () => {
196 it("[[Get]] is positive zero", () => {
197 assertStrictEquals(POSITIVE_ZERO, 0);
198 });
199 });
200
201 describe("RECIPROCAL_SQRT_2", () => {
202 it("[[Get]] is sqrt(Β½)", () => {
203 assertStrictEquals(RECIPROCAL_SQRT_2, Math.SQRT1_2);
204 });
205 });
206
207 describe("REPLACE", () => {
208 it("[[Get]] is @@replace", () => {
209 assertStrictEquals(REPLACE, Symbol.replace);
210 });
211 });
212
213 describe("SPECIES", () => {
214 it("[[Get]] is @@species", () => {
215 assertStrictEquals(SPECIES, Symbol.species);
216 });
217 });
218
219 describe("SPLIT", () => {
220 it("[[Get]] is @@split", () => {
221 assertStrictEquals(SPLIT, Symbol.split);
222 });
223 });
224
225 describe("SQRT_2", () => {
226 it("[[Get]] is sqrt(2)", () => {
227 assertStrictEquals(SQRT_2, Math.SQRT2);
228 });
229 });
230
231 describe("TO_PRIMITIVE", () => {
232 it("[[Get]] is @@toPrimitive", () => {
233 assertStrictEquals(TO_PRIMITIVE, Symbol.toPrimitive);
234 });
235 });
236
237 describe("TO_STRING_TAG", () => {
238 it("[[Get]] is @@toStringTag", () => {
239 assertStrictEquals(TO_STRING_TAG, Symbol.toStringTag);
240 });
241 });
242
243 describe("UNDEFINED", () => {
244 it("[[Get]] is undefined", () => {
245 assertStrictEquals(UNDEFINED, void {});
246 });
247 });
248
249 describe("UNSCOPABLES", () => {
250 it("[[Get]] is @@unscopables", () => {
251 assertStrictEquals(UNSCOPABLES, Symbol.unscopables);
252 });
253 });
254
255 describe("canonicalNumericIndexString", () => {
256 it("[[Call]] returns undefined for nonstrings", () => {
257 assertStrictEquals(canonicalNumericIndexString(1), void {});
258 });
259
260 it("[[Call]] returns undefined for noncanonical strings", () => {
261 assertStrictEquals(canonicalNumericIndexString(""), void {});
262 assertStrictEquals(canonicalNumericIndexString("01"), void {});
263 assertStrictEquals(
264 canonicalNumericIndexString("9007199254740993"),
265 void {},
266 );
267 });
268
269 it('[[Call]] returns -0 for "-0"', () => {
270 assertStrictEquals(canonicalNumericIndexString("-0"), -0);
271 });
272
273 it("[[Call]] returns the corresponding number for canonical strings", () => {
274 assertStrictEquals(canonicalNumericIndexString("0"), 0);
275 assertStrictEquals(canonicalNumericIndexString("-0.25"), -0.25);
276 assertStrictEquals(
277 canonicalNumericIndexString("9007199254740992"),
278 9007199254740992,
279 );
280 assertStrictEquals(canonicalNumericIndexString("NaN"), 0 / 0);
281 assertStrictEquals(canonicalNumericIndexString("Infinity"), 1 / 0);
282 assertStrictEquals(
283 canonicalNumericIndexString("-Infinity"),
284 -1 / 0,
285 );
286 });
287
288 it("[[Construct]] throws an error", () => {
289 assertThrows(() => new canonicalNumericIndexString(""));
290 });
291
292 describe(".length", () => {
293 it("[[Get]] returns the correct length", () => {
294 assertStrictEquals(canonicalNumericIndexString.length, 1);
295 });
296 });
297
298 describe(".name", () => {
299 it("[[Get]] returns the correct name", () => {
300 assertStrictEquals(
301 canonicalNumericIndexString.name,
302 "canonicalNumericIndexString",
303 );
304 });
305 });
306 });
307
308 describe("completePropertyDescriptor", () => {
309 it("[[Call]] completes a generic descriptor", () => {
310 const desc = {};
311 completePropertyDescriptor(desc);
312 assertEquals(desc, {
313 configurable: false,
314 enumerable: false,
315 value: undefined,
316 writable: false,
317 });
318 });
319
320 it("[[Call]] completes a data descriptor", () => {
321 const desc = { value: undefined };
322 completePropertyDescriptor(desc);
323 assertEquals(desc, {
324 configurable: false,
325 enumerable: false,
326 value: undefined,
327 writable: false,
328 });
329 });
330
331 it("[[Call]] completes an accessor descriptor", () => {
332 const desc = { get: undefined };
333 completePropertyDescriptor(desc);
334 assertEquals(desc, {
335 configurable: false,
336 enumerable: false,
337 get: undefined,
338 set: undefined,
339 });
340 });
341
342 it("[[Call]] throws an error when the descriptor is undefined", () => {
343 assertThrows(() => new completePropertyDescriptor(undefined));
344 });
345
346 it("[[Construct]] throws an error", () => {
347 assertThrows(() => new completePropertyDescriptor({}));
348 });
349
350 describe(".length", () => {
351 it("[[Get]] returns the correct length", () => {
352 assertStrictEquals(completePropertyDescriptor.length, 1);
353 });
354 });
355
356 describe(".name", () => {
357 it("[[Get]] returns the correct name", () => {
358 assertStrictEquals(
359 completePropertyDescriptor.name,
360 "completePropertyDescriptor",
361 );
362 });
363 });
364 });
365
366 describe("isAccessorDescriptor", () => {
367 it("[[Call]] returns false for a generic descriptor", () => {
368 assertStrictEquals(isAccessorDescriptor({}), false);
369 });
370
371 it("[[Get]] returns false for a data descriptor", () => {
372 assertStrictEquals(
373 isAccessorDescriptor({ value: undefined }),
374 false,
375 );
376 assertStrictEquals(
377 isAccessorDescriptor({ writable: undefined }),
378 false,
379 );
380 });
381
382 it("[[Get]] returns true for an accessor descriptor", () => {
383 assertStrictEquals(isAccessorDescriptor({ get: undefined }), true);
384 assertStrictEquals(isAccessorDescriptor({ set: undefined }), true);
385 });
386
387 it("[[Get]] returns false for undefined", () => {
388 assertStrictEquals(isAccessorDescriptor(undefined), false);
389 });
390
391 it("[[Construct]] throws an error", () => {
392 assertThrows(() => new isAccessorDescriptor({}));
393 });
394
395 describe(".length", () => {
396 it("[[Get]] returns the correct length", () => {
397 assertStrictEquals(isAccessorDescriptor.length, 1);
398 });
399 });
400
401 describe(".name", () => {
402 it("[[Get]] returns the correct name", () => {
403 assertStrictEquals(
404 isAccessorDescriptor.name,
405 "isAccessorDescriptor",
406 );
407 });
408 });
409 });
410
411 describe("isArrayIndexString", () => {
412 it("[[Call]] returns false for nonstrings", () => {
413 assertStrictEquals(isArrayIndexString(1), false);
414 });
415
416 it("[[Call]] returns false for noncanonical strings", () => {
417 assertStrictEquals(isArrayIndexString(""), false);
418 assertStrictEquals(isArrayIndexString("01"), false);
419 assertStrictEquals(isArrayIndexString("9007199254740993"), false);
420 });
421
422 it("[[Call]] returns false for nonfinite numbers", () => {
423 assertStrictEquals(isArrayIndexString("NaN"), false);
424 assertStrictEquals(isArrayIndexString("Infinity"), false);
425 assertStrictEquals(isArrayIndexString("-Infinity"), false);
426 });
427
428 it("[[Call]] returns false for negative numbers", () => {
429 assertStrictEquals(isArrayIndexString("-0"), false);
430 assertStrictEquals(isArrayIndexString("-1"), false);
431 });
432
433 it("[[Call]] returns false for nonintegers", () => {
434 assertStrictEquals(isArrayIndexString("0.25"), false);
435 assertStrictEquals(isArrayIndexString("1.1"), false);
436 });
437
438 it("[[Call]] returns false for numbers greater than or equal to -1 >>> 0", () => {
439 assertStrictEquals(isArrayIndexString(String(-1 >>> 0)), false);
440 assertStrictEquals(
441 isArrayIndexString(String((-1 >>> 0) + 1)),
442 false,
443 );
444 });
445
446 it("[[Call]] returns true for array lengths less than -1 >>> 0", () => {
447 assertStrictEquals(isArrayIndexString("0"), true);
448 assertStrictEquals(
449 isArrayIndexString(String((-1 >>> 0) - 1)),
450 true,
451 );
452 });
453
454 it("[[Construct]] throws an error", () => {
455 assertThrows(() => new isArrayIndexString("0"));
456 });
457
458 describe(".length", () => {
459 it("[[Get]] returns the correct length", () => {
460 assertStrictEquals(isArrayIndexString.length, 1);
461 });
462 });
463
464 describe(".name", () => {
465 it("[[Get]] returns the correct name", () => {
466 assertStrictEquals(
467 isArrayIndexString.name,
468 "isArrayIndexString",
469 );
470 });
471 });
472 });
473
474 describe("isDataDescriptor", () => {
475 it("[[Call]] returns false for a generic descriptor", () => {
476 assertStrictEquals(isDataDescriptor({}), false);
477 });
478
479 it("[[Get]] returns true for a data descriptor", () => {
480 assertStrictEquals(isDataDescriptor({ value: undefined }), true);
481 assertStrictEquals(isDataDescriptor({ writable: true }), true);
482 });
483
484 it("[[Get]] returns false for an accessor descriptor", () => {
485 assertStrictEquals(isDataDescriptor({ get: undefined }), false);
486 assertStrictEquals(isDataDescriptor({ set: undefined }), false);
487 });
488
489 it("[[Get]] returns false for undefined", () => {
490 assertStrictEquals(isDataDescriptor(undefined), false);
491 });
492
493 it("[[Construct]] throws an error", () => {
494 assertThrows(() => new isDataDescriptor({}));
495 });
496
497 describe(".length", () => {
498 it("[[Get]] returns the correct length", () => {
499 assertStrictEquals(isDataDescriptor.length, 1);
500 });
501 });
502
503 describe(".name", () => {
504 it("[[Get]] returns the correct name", () => {
505 assertStrictEquals(isDataDescriptor.name, "isDataDescriptor");
506 });
507 });
508 });
509
510 describe("isFullyPopulatedDescriptor", () => {
511 it("[[Call]] returns false for a generic descriptor", () => {
512 assertStrictEquals(isFullyPopulatedDescriptor({}), false);
513 });
514
515 it("[[Get]] returns false for a non‐fully‐populated data descriptor", () => {
516 assertStrictEquals(
517 isFullyPopulatedDescriptor({ value: undefined }),
518 false,
519 );
520 assertStrictEquals(
521 isFullyPopulatedDescriptor({ writable: true }),
522 false,
523 );
524 });
525
526 it("[[Get]] returns true for a fully‐populated data descriptor", () => {
527 assertStrictEquals(
528 isFullyPopulatedDescriptor({
529 configurable: true,
530 enumerable: true,
531 value: undefined,
532 writable: true,
533 }),
534 true,
535 );
536 });
537
538 it("[[Get]] returns false for a non‐fully‐populated accessor descriptor", () => {
539 assertStrictEquals(
540 isFullyPopulatedDescriptor({ get: undefined }),
541 false,
542 );
543 assertStrictEquals(
544 isFullyPopulatedDescriptor({ set: undefined }),
545 false,
546 );
547 });
548
549 it("[[Get]] returns true for a fully‐populated accessor descriptor", () => {
550 assertStrictEquals(
551 isFullyPopulatedDescriptor({
552 configurable: true,
553 enumerable: true,
554 get: undefined,
555 set: undefined,
556 }),
557 true,
558 );
559 });
560
561 it("[[Get]] returns false for undefined", () => {
562 assertStrictEquals(isFullyPopulatedDescriptor(undefined), false);
563 });
564
565 it("[[Construct]] throws an error", () => {
566 assertThrows(() => new isFullyPopulatedDescriptor({}));
567 });
568
569 describe(".length", () => {
570 it("[[Get]] returns the correct length", () => {
571 assertStrictEquals(isFullyPopulatedDescriptor.length, 1);
572 });
573 });
574
575 describe(".name", () => {
576 it("[[Get]] returns the correct name", () => {
577 assertStrictEquals(
578 isFullyPopulatedDescriptor.name,
579 "isFullyPopulatedDescriptor",
580 );
581 });
582 });
583 });
584
585 describe("isGenericDescriptor", () => {
586 it("[[Call]] returns true for a generic descriptor", () => {
587 assertStrictEquals(isGenericDescriptor({}), true);
588 });
589
590 it("[[Get]] returns false for a data descriptor", () => {
591 assertStrictEquals(
592 isGenericDescriptor({ value: undefined }),
593 false,
594 );
595 assertStrictEquals(isGenericDescriptor({ writable: true }), false);
596 });
597
598 it("[[Get]] returns false for an accessor descriptor", () => {
599 assertStrictEquals(isGenericDescriptor({ get: undefined }), false);
600 assertStrictEquals(isGenericDescriptor({ set: undefined }), false);
601 });
602
603 it("[[Get]] returns false for undefined", () => {
604 assertStrictEquals(isGenericDescriptor(undefined), false);
605 });
606
607 it("[[Construct]] throws an error", () => {
608 assertThrows(() => new isGenericDescriptor({}));
609 });
610
611 describe(".length", () => {
612 it("[[Get]] returns the correct length", () => {
613 assertStrictEquals(isGenericDescriptor.length, 1);
614 });
615 });
616
617 describe(".name", () => {
618 it("[[Get]] returns the correct name", () => {
619 assertStrictEquals(
620 isGenericDescriptor.name,
621 "isGenericDescriptor",
622 );
623 });
624 });
625 });
626
627 describe("isIntegerIndexString", () => {
628 it("[[Call]] returns false for nonstrings", () => {
629 assertStrictEquals(isIntegerIndexString(1), false);
630 });
631
632 it("[[Call]] returns false for noncanonical strings", () => {
633 assertStrictEquals(isIntegerIndexString(""), false);
634 assertStrictEquals(isIntegerIndexString("01"), false);
635 assertStrictEquals(
636 isIntegerIndexString("9007199254740993"),
637 false,
638 );
639 });
640
641 it("[[Call]] returns false for nonfinite numbers", () => {
642 assertStrictEquals(isIntegerIndexString("NaN"), false);
643 assertStrictEquals(isIntegerIndexString("Infinity"), false);
644 assertStrictEquals(isIntegerIndexString("-Infinity"), false);
645 });
646
647 it("[[Call]] returns false for negative numbers", () => {
648 assertStrictEquals(isIntegerIndexString("-0"), false);
649 assertStrictEquals(isIntegerIndexString("-1"), false);
650 });
651
652 it("[[Call]] returns false for nonintegers", () => {
653 assertStrictEquals(isIntegerIndexString("0.25"), false);
654 assertStrictEquals(isIntegerIndexString("1.1"), false);
655 });
656
657 it("[[Call]] returns false for numbers greater than or equal to 2 ** 53", () => {
658 assertStrictEquals(
659 isIntegerIndexString("9007199254740992"),
660 false,
661 );
662 });
663
664 it("[[Call]] returns true for safe canonical integer strings", () => {
665 assertStrictEquals(isIntegerIndexString("0"), true);
666 assertStrictEquals(isIntegerIndexString("9007199254740991"), true);
667 });
668
669 it("[[Construct]] throws an error", () => {
670 assertThrows(() => new isIntegerIndexString("0"));
671 });
672
673 describe(".length", () => {
674 it("[[Get]] returns the correct length", () => {
675 assertStrictEquals(isIntegerIndexString.length, 1);
676 });
677 });
678
679 describe(".name", () => {
680 it("[[Get]] returns the correct name", () => {
681 assertStrictEquals(
682 isIntegerIndexString.name,
683 "isIntegerIndexString",
684 );
685 });
686 });
687 });
688
689 describe("ordinaryToPrimitive", () => {
690 it("[[Call]] prefers `valueOf` by default", () => {
691 const obj = {
692 toString() {
693 return "failure";
694 },
695 valueOf() {
696 return "success";
697 },
698 };
699 assertStrictEquals(ordinaryToPrimitive(obj), "success");
700 assertStrictEquals(ordinaryToPrimitive(obj, "default"), "success");
701 });
702
703 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
704 const obj = {
705 toString() {
706 return "failure";
707 },
708 valueOf() {
709 return "success";
710 },
711 };
712 assertStrictEquals(ordinaryToPrimitive(obj, "number"), "success");
713 });
714
715 it('[[Call]] prefers `toString` for a "string" hint', () => {
716 const obj = {
717 toString() {
718 return "success";
719 },
720 valueOf() {
721 return "failure";
722 },
723 };
724 assertStrictEquals(ordinaryToPrimitive(obj, "string"), "success");
725 });
726
727 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
728 const obj = {
729 toString() {
730 return "success";
731 },
732 valueOf: "failure",
733 };
734 assertStrictEquals(ordinaryToPrimitive(obj), "success");
735 });
736
737 it("[[Call]] falls back to the other method if the first returns an object", () => {
738 const obj = {
739 toString() {
740 return "success";
741 },
742 valueOf() {
743 return new String("failure");
744 },
745 };
746 assertStrictEquals(ordinaryToPrimitive(obj), "success");
747 });
748
749 it("[[Call]] throws an error if neither method is callable", () => {
750 const obj = {
751 toString: "failure",
752 valueOf: "failure",
753 };
754 assertThrows(() => ordinaryToPrimitive(obj));
755 });
756
757 it("[[Call]] throws an error if neither method returns an object", () => {
758 const obj = {
759 toString() {
760 return new String("failure");
761 },
762 valueOf() {
763 return new String("failure");
764 },
765 };
766 assertThrows(() => ordinaryToPrimitive(obj));
767 });
768
769 it("[[Construct]] throws an error", () => {
770 assertThrows(() => new ordinaryToPrimitive(""));
771 });
772
773 describe(".length", () => {
774 it("[[Get]] returns the correct length", () => {
775 assertStrictEquals(ordinaryToPrimitive.length, 2);
776 });
777 });
778
779 describe(".name", () => {
780 it("[[Get]] returns the correct name", () => {
781 assertStrictEquals(
782 ordinaryToPrimitive.name,
783 "ordinaryToPrimitive",
784 );
785 });
786 });
787 });
788
789 describe("sameValue", () => {
790 it("[[Call]] returns false for null πŸ†š undefined", () => {
791 assertStrictEquals(sameValue(null, undefined), false);
792 });
793
794 it("[[Call]] returns false for null πŸ†š an object", () => {
795 assertStrictEquals(sameValue(null, {}), false);
796 });
797
798 it("[[Call]] returns true for null πŸ†š null", () => {
799 assertStrictEquals(sameValue(null, null), true);
800 });
801
802 it("[[Call]] returns false for two different objects", () => {
803 assertStrictEquals(sameValue({}, {}), false);
804 });
805
806 it("[[Call]] returns true for the same object", () => {
807 const obj = {};
808 assertStrictEquals(sameValue(obj, obj), true);
809 });
810
811 it("[[Call]] returns false for Β±0", () => {
812 assertStrictEquals(sameValue(0, -0), false);
813 });
814
815 it("[[Call]] returns true for -0", () => {
816 assertStrictEquals(sameValue(-0, -0), true);
817 });
818
819 it("[[Call]] returns true for nan", () => {
820 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
821 });
822
823 it("[[Call]] returns false for a primitive and its wrapped object", () => {
824 assertStrictEquals(sameValue(false, new Boolean(false)), false);
825 });
826
827 it("[[Construct]] throws an error", () => {
828 assertThrows(() => new sameValue(true, true));
829 });
830
831 describe(".length", () => {
832 it("[[Get]] returns the correct length", () => {
833 assertStrictEquals(sameValue.length, 2);
834 });
835 });
836
837 describe(".name", () => {
838 it("[[Get]] returns the correct name", () => {
839 assertStrictEquals(sameValue.name, "sameValue");
840 });
841 });
842 });
843
844 describe("sameValueZero", () => {
845 it("[[Call]] returns false for null πŸ†š undefined", () => {
846 assertStrictEquals(sameValueZero(null, undefined), false);
847 });
848
849 it("[[Call]] returns false for null πŸ†š an object", () => {
850 assertStrictEquals(sameValueZero(null, {}), false);
851 });
852
853 it("[[Call]] returns true for null πŸ†š null", () => {
854 assertStrictEquals(sameValueZero(null, null), true);
855 });
856
857 it("[[Call]] returns false for two different objects", () => {
858 assertStrictEquals(sameValueZero({}, {}), false);
859 });
860
861 it("[[Call]] returns true for the same object", () => {
862 const obj = {};
863 assertStrictEquals(sameValueZero(obj, obj), true);
864 });
865
866 it("[[Call]] returns true for Β±0", () => {
867 assertStrictEquals(sameValueZero(0, -0), true);
868 });
869
870 it("[[Call]] returns true for -0", () => {
871 assertStrictEquals(sameValueZero(-0, -0), true);
872 });
873
874 it("[[Call]] returns true for nan", () => {
875 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
876 });
877
878 it("[[Call]] returns false for a primitive and its wrapped object", () => {
879 assertStrictEquals(
880 sameValueZero(false, new Boolean(false)),
881 false,
882 );
883 });
884
885 it("[[Construct]] throws an error", () => {
886 assertThrows(() => new sameValueZero(true, true));
887 });
888
889 describe(".length", () => {
890 it("[[Get]] returns the correct length", () => {
891 assertStrictEquals(sameValueZero.length, 2);
892 });
893 });
894
895 describe(".name", () => {
896 it("[[Get]] returns the correct name", () => {
897 assertStrictEquals(sameValueZero.name, "sameValueZero");
898 });
899 });
900 });
901
902 describe("toFunctionName", () => {
903 it("[[Call]] works with strings and no prefix", () => {
904 assertStrictEquals(toFunctionName("etaoin"), "etaoin");
905 });
906
907 it("[[Call]] works with objects and no prefix", () => {
908 assertStrictEquals(
909 toFunctionName({
910 toString() {
911 return "etaoin";
912 },
913 }),
914 "etaoin",
915 );
916 });
917
918 it("[[Call]] works with descriptionless symbols and no prefix", () => {
919 assertStrictEquals(toFunctionName(Symbol()), "");
920 });
921
922 it("[[Call]] works with empty description symbols and no prefix", () => {
923 assertStrictEquals(toFunctionName(Symbol("")), "[]");
924 });
925
926 it("[[Call]] works with described symbols and no prefix", () => {
927 assertStrictEquals(toFunctionName(Symbol("etaoin")), "[etaoin]");
928 });
929
930 it("[[Call]] works with strings and a prefix", () => {
931 assertStrictEquals(toFunctionName("etaoin", "foo"), "foo etaoin");
932 });
933
934 it("[[Call]] works with objects and no prefix", () => {
935 assertStrictEquals(
936 toFunctionName({
937 toString() {
938 return "etaoin";
939 },
940 }, "foo"),
941 "foo etaoin",
942 );
943 });
944
945 it("[[Call]] works with descriptionless symbols and no prefix", () => {
946 assertStrictEquals(toFunctionName(Symbol(), "foo"), "foo ");
947 });
948
949 it("[[Call]] works with empty description symbols and no prefix", () => {
950 assertStrictEquals(toFunctionName(Symbol(""), "foo"), "foo []");
951 });
952
953 it("[[Call]] works with described symbols and no prefix", () => {
954 assertStrictEquals(
955 toFunctionName(Symbol("etaoin"), "foo"),
956 "foo [etaoin]",
957 );
958 });
959
960 it("[[Construct]] throws an error", () => {
961 assertThrows(() => new toFunctionName(""));
962 });
963
964 describe(".length", () => {
965 it("[[Get]] returns the correct length", () => {
966 assertStrictEquals(toFunctionName.length, 1);
967 });
968 });
969
970 describe(".name", () => {
971 it("[[Get]] returns the correct name", () => {
972 assertStrictEquals(
973 toFunctionName.name,
974 "toFunctionName",
975 );
976 });
977 });
978 });
979
980 describe("toIndex", () => {
981 it("[[Call]] returns an index", () => {
982 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
983 });
984
985 it("[[Call]] returns zero for a zerolike argument", () => {
986 assertStrictEquals(toIndex(NaN), 0);
987 assertStrictEquals(toIndex("failure"), 0);
988 assertStrictEquals(toIndex(-0), 0);
989 });
990
991 it("[[Call]] rounds down to the nearest integer", () => {
992 assertStrictEquals(toIndex(0.25), 0);
993 assertStrictEquals(toIndex(1.1), 1);
994 });
995
996 it("[[Call]] throws when provided a negative number", () => {
997 assertThrows(() => toIndex(-1));
998 assertThrows(() => toIndex(-Infinity));
999 });
1000
1001 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
1002 assertThrows(() => toIndex(9007199254740992));
1003 assertThrows(() => toIndex(Infinity));
1004 });
1005
1006 it("[[Construct]] throws an error", () => {
1007 assertThrows(() => new toIndex(0));
1008 });
1009
1010 describe(".length", () => {
1011 it("[[Get]] returns the correct length", () => {
1012 assertStrictEquals(toIndex.length, 1);
1013 });
1014 });
1015
1016 describe(".name", () => {
1017 it("[[Get]] returns the correct name", () => {
1018 assertStrictEquals(toIndex.name, "toIndex");
1019 });
1020 });
1021 });
1022
1023 describe("toLength", () => {
1024 it("[[Call]] returns a length", () => {
1025 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
1026 });
1027
1028 it("[[Call]] returns zero for a nan argument", () => {
1029 assertStrictEquals(toLength(NaN), 0);
1030 assertStrictEquals(toLength("failure"), 0);
1031 });
1032
1033 it("[[Call]] rounds down to the nearest integer", () => {
1034 assertStrictEquals(toLength(0.25), 0);
1035 assertStrictEquals(toLength(1.1), 1);
1036 });
1037
1038 it("[[Call]] returns a result greater than or equal to zero", () => {
1039 assertStrictEquals(toLength(-0), 0);
1040 assertStrictEquals(toLength(-1), 0);
1041 assertStrictEquals(toLength(-Infinity), 0);
1042 });
1043
1044 it("[[Call]] returns a result less than 2 ** 53", () => {
1045 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
1046 assertStrictEquals(toLength(Infinity), 9007199254740991);
1047 });
1048
1049 it("[[Construct]] throws an error", () => {
1050 assertThrows(() => new toLength(0));
1051 });
1052
1053 describe(".length", () => {
1054 it("[[Get]] returns the correct length", () => {
1055 assertStrictEquals(toLength.length, 1);
1056 });
1057 });
1058
1059 describe(".name", () => {
1060 it("[[Get]] returns the correct name", () => {
1061 assertStrictEquals(toLength.name, "toLength");
1062 });
1063 });
1064 });
1065
1066 describe("toPrimitive", () => {
1067 it("[[Call]] returns the argument when passed a primitive", () => {
1068 const value = Symbol();
1069 assertStrictEquals(toPrimitive(value), value);
1070 });
1071
1072 it("[[Call]] works with nullish values", () => {
1073 assertStrictEquals(toPrimitive(null), null);
1074 assertStrictEquals(toPrimitive(), void {});
1075 });
1076
1077 it("[[Call]] calls ordinaryToPrimitive by default", () => {
1078 const value = Object.assign(
1079 Object.create(null),
1080 {
1081 valueOf() {
1082 return "success";
1083 },
1084 },
1085 );
1086 assertStrictEquals(toPrimitive(value), "success");
1087 });
1088
1089 it("[[Call]] accepts a hint", () => {
1090 const value = Object.assign(
1091 Object.create(null),
1092 {
1093 toString() {
1094 return "success";
1095 },
1096 valueOf() {
1097 return "failure";
1098 },
1099 },
1100 );
1101 assertStrictEquals(toPrimitive(value, "string"), "success");
1102 });
1103
1104 it("[[Call]] uses the exotic toPrimitive method if available", () => {
1105 const value = Object.assign(
1106 Object.create(null),
1107 {
1108 [Symbol.toPrimitive]() {
1109 return "success";
1110 },
1111 },
1112 );
1113 assertStrictEquals(toPrimitive(value), "success");
1114 });
1115
1116 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
1117 const value = Object.assign(
1118 Object.create(null),
1119 {
1120 [Symbol.toPrimitive](hint) {
1121 return hint === "string" ? "success" : "failure";
1122 },
1123 },
1124 );
1125 assertStrictEquals(toPrimitive(value, "string"), "success");
1126 });
1127
1128 it('[[Call]] passes a "default" hint by default', () => {
1129 const value = Object.assign(
1130 Object.create(null),
1131 {
1132 [Symbol.toPrimitive](hint) {
1133 return hint === "default" ? "success" : "failure";
1134 },
1135 },
1136 );
1137 assertStrictEquals(toPrimitive(value), "success");
1138 });
1139
1140 it("[[Call]] throws for an invalid hint", () => {
1141 const value1 = Object.assign(
1142 Object.create(null),
1143 {
1144 [Symbol.toPrimitive]() {
1145 return "success";
1146 },
1147 },
1148 );
1149 const value2 = Object.assign(
1150 Object.create(null),
1151 {
1152 valueOf() {
1153 return true;
1154 },
1155 },
1156 );
1157 assertThrows(() => toPrimitive(value1, "badhint"));
1158 assertThrows(() => toPrimitive(value2, "badhint"));
1159 assertThrows(() => toPrimitive(true, "badhint"));
1160 });
1161
1162 it("[[Construct]] throws an error", () => {
1163 assertThrows(() => new toPrimitive(true));
1164 });
1165
1166 describe(".length", () => {
1167 it("[[Get]] returns the correct length", () => {
1168 assertStrictEquals(toPrimitive.length, 1);
1169 });
1170 });
1171
1172 describe(".name", () => {
1173 it("[[Get]] returns the correct name", () => {
1174 assertStrictEquals(toPrimitive.name, "toPrimitive");
1175 });
1176 });
1177 });
1178
1179 describe("toPropertyKey", () => {
1180 it("returns a string or symbol", () => {
1181 const sym = Symbol();
1182 assertStrictEquals(toPropertyKey(sym), sym);
1183 assertStrictEquals(
1184 toPropertyKey(new String("success")),
1185 "success",
1186 );
1187 });
1188
1189 it("favours the `toString` representation", () => {
1190 assertStrictEquals(
1191 toPropertyKey({
1192 toString() {
1193 return "success";
1194 },
1195 valueOf() {
1196 return "failure";
1197 },
1198 }),
1199 "success",
1200 );
1201 });
1202
1203 it("[[Construct]] throws an error", () => {
1204 assertThrows(() => new toPropertyKey(""));
1205 });
1206
1207 describe(".length", () => {
1208 it("[[Get]] returns the correct length", () => {
1209 assertStrictEquals(toPropertyKey.length, 1);
1210 });
1211 });
1212
1213 describe(".name", () => {
1214 it("[[Get]] returns the correct name", () => {
1215 assertStrictEquals(toPropertyKey.name, "toPropertyKey");
1216 });
1217 });
1218 });
1219
1220 describe("type", () => {
1221 it('[[Call]] returns "null" for null', () => {
1222 assertStrictEquals(type(null), "null");
1223 });
1224
1225 it('[[Call]] returns "undefined" for undefined', () => {
1226 assertStrictEquals(type(void {}), "undefined");
1227 });
1228
1229 it('[[Call]] returns "object" for non‐callable objects', () => {
1230 assertStrictEquals(type(Object.create(null)), "object");
1231 });
1232
1233 it('[[Call]] returns "object" for callable objects', () => {
1234 assertStrictEquals(type(() => {}), "object");
1235 });
1236
1237 it('[[Call]] returns "object" for constructable objects', () => {
1238 assertStrictEquals(type(class {}), "object");
1239 });
1240
1241 it("[[Construct]] throws an error", () => {
1242 assertThrows(() => new type({}));
1243 });
1244
1245 describe(".length", () => {
1246 it("[[Get]] returns the correct length", () => {
1247 assertStrictEquals(type.length, 1);
1248 });
1249 });
1250
1251 describe(".name", () => {
1252 it("[[Get]] returns the correct name", () => {
1253 assertStrictEquals(type.name, "type");
1254 });
1255 });
1256 });
1257
1258 describe("𝑒", () => {
1259 it("[[Get]] is 𝑒", () => {
1260 assertStrictEquals(𝑒, Math.E);
1261 });
1262 });
1263
1264 describe("πœ€", () => {
1265 it("[[Get]] is πœ€", () => {
1266 assertStrictEquals(πœ€, Number.EPSILON);
1267 });
1268 });
1269
1270 describe("πœ‹", () => {
1271 it("[[Get]] is πœ‹", () => {
1272 assertStrictEquals(πœ‹, Math.PI);
1273 });
1274 });
This page took 0.302092 seconds and 5 git commands to generate.