1 // ♓🌟 Piscēs ∷ value.test.js
2 // ====================================================================
4 // Copyright © 2022–2023 Lady [@ Lady’s Computer].
6 // This Source Code Form is subject to the terms of the Mozilla Public
7 // License, v. 2.0. If a copy of the MPL was not distributed with this
8 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
15 } from "./dev-deps.js";
28 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
30 MINIMUM_SAFE_INTEGRAL_NUMBER
,
59 describe("ASYNC_ITERATOR", () => {
60 it("[[Get]] is @@asyncIterator", () => {
61 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
65 describe("HAS_INSTANCE", () => {
66 it("[[Get]] is @@hasInstance", () => {
67 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
71 describe("IS_CONCAT_SPREADABLE", () => {
72 it("[[Get]] is @@isConcatSpreadable", () => {
75 Symbol
.isConcatSpreadable
,
80 describe("ITERATOR", () => {
81 it("[[Get]] is @@iterator", () => {
82 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
86 describe("LN10", () => {
87 it("[[Get]] is ln(10)", () => {
88 assertStrictEquals(LN10
, Math
.LN10
);
92 describe("LN2", () => {
93 it("[[Get]] is ln(2)", () => {
94 assertStrictEquals(LN2
, Math
.LN2
);
98 describe("LOG10ℇ", () => {
99 it("[[Get]] is log10(ℇ)", () => {
100 assertStrictEquals(LOG10
ℇ, Math
.LOG10E
);
104 describe("LOG2ℇ", () => {
105 it("[[Get]] is log2(ℇ)", () => {
106 assertStrictEquals(LOG2
ℇ, Math
.LOG2E
);
110 describe("MATCH", () => {
111 it("[[Get]] is @@match", () => {
112 assertStrictEquals(MATCH
, Symbol
.match
);
116 describe("MATCH_ALL", () => {
117 it("[[Get]] is @@matchAll", () => {
118 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
122 describe("MAXIMUM_NUMBER", () => {
123 it("[[Get]] is the maximum number", () => {
124 assertStrictEquals(MAXIMUM_NUMBER
, Number
.MAX_VALUE
);
128 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
129 it("[[Get]] is the maximum safe integral number", () => {
131 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
132 Number
.MAX_SAFE_INTEGER
,
137 describe("MINIMUM_NUMBER", () => {
138 it("[[Get]] is the minimum number", () => {
139 assertStrictEquals(MINIMUM_NUMBER
, Number
.MIN_VALUE
);
143 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
144 it("[[Get]] is the minimum safe integral number", () => {
146 MINIMUM_SAFE_INTEGRAL_NUMBER
,
147 Number
.MIN_SAFE_INTEGER
,
152 describe("NAN", () => {
153 it("[[Get]] is nan", () => {
154 assertStrictEquals(NAN
, NaN
);
158 describe("NEGATIVE_INFINITY", () => {
159 it("[[Get]] is negative infinity", () => {
160 assertStrictEquals(NEGATIVE_INFINITY
, -Infinity
);
164 describe("NEGATIVE_ZERO", () => {
165 it("[[Get]] is negative zero", () => {
166 assertStrictEquals(NEGATIVE_ZERO
, -0);
170 describe("NULL", () => {
171 it("[[Get]] is null", () => {
172 assertStrictEquals(NULL
, null);
176 describe("POSITIVE_INFINITY", () => {
177 it("[[Get]] is negative infinity", () => {
178 assertStrictEquals(POSITIVE_INFINITY
, Infinity
);
182 describe("POSITIVE_ZERO", () => {
183 it("[[Get]] is positive zero", () => {
184 assertStrictEquals(POSITIVE_ZERO
, 0);
188 describe("RECIPROCAL_SQRT2", () => {
189 it("[[Get]] is sqrt(½)", () => {
190 assertStrictEquals(RECIPROCAL_SQRT2
, Math
.SQRT1_2
);
194 describe("REPLACE", () => {
195 it("[[Get]] is @@replace", () => {
196 assertStrictEquals(REPLACE
, Symbol
.replace
);
200 describe("SPECIES", () => {
201 it("[[Get]] is @@species", () => {
202 assertStrictEquals(SPECIES
, Symbol
.species
);
206 describe("SPLIT", () => {
207 it("[[Get]] is @@split", () => {
208 assertStrictEquals(SPLIT
, Symbol
.split
);
212 describe("SQRT2", () => {
213 it("[[Get]] is sqrt(2)", () => {
214 assertStrictEquals(SQRT2
, Math
.SQRT2
);
218 describe("TO_PRIMITIVE", () => {
219 it("[[Get]] is @@toPrimitive", () => {
220 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
224 describe("TO_STRING_TAG", () => {
225 it("[[Get]] is @@toStringTag", () => {
226 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
230 describe("UNDEFINED", () => {
231 it("[[Get]] is undefined", () => {
232 assertStrictEquals(UNDEFINED
, void {});
236 describe("UNSCOPABLES", () => {
237 it("[[Get]] is @@unscopables", () => {
238 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
242 describe("Ε", () => {
243 it("[[Get]] is ε", () => {
244 assertStrictEquals(Ε, Number
.EPSILON
);
248 describe("Π", () => {
249 it("[[Get]] is π", () => {
250 assertStrictEquals(Π, Math
.PI
);
254 describe("ℇ", () => {
255 it("[[Get]] is ℇ", () => {
256 assertStrictEquals(ℇ, Math
.E
);
260 describe("ordinaryToPrimitive", () => {
261 it("[[Call]] prefers `valueOf` by default", () => {
270 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
271 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
274 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
283 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
286 it('[[Call]] prefers `toString` for a "string" hint', () => {
295 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
298 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
305 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
308 it("[[Call]] falls back to the other method if the first returns an object", () => {
314 return new String("failure");
317 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
320 it("[[Call]] throws an error if neither method is callable", () => {
325 assertThrows(() => ordinaryToPrimitive(obj
));
328 it("[[Call]] throws an error if neither method returns an object", () => {
331 return new String("failure");
334 return new String("failure");
337 assertThrows(() => ordinaryToPrimitive(obj
));
340 it("[[Construct]] throws an error", () => {
341 assertThrows(() => new ordinaryToPrimitive(""));
344 describe(".length", () => {
345 it("[[Get]] returns the correct length", () => {
346 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
350 describe(".name", () => {
351 it("[[Get]] returns the correct name", () => {
353 ordinaryToPrimitive
.name
,
354 "ordinaryToPrimitive",
360 describe("sameValue", () => {
361 it("[[Call]] returns false for null 🆚 undefined", () => {
362 assertStrictEquals(sameValue(null, undefined), false);
365 it("[[Call]] returns false for null 🆚 an object", () => {
366 assertStrictEquals(sameValue(null, {}), false);
369 it("[[Call]] returns true for null 🆚 null", () => {
370 assertStrictEquals(sameValue(null, null), true);
373 it("[[Call]] returns false for two different objects", () => {
374 assertStrictEquals(sameValue({}, {}), false);
377 it("[[Call]] returns true for the same object", () => {
379 assertStrictEquals(sameValue(obj
, obj
), true);
382 it("[[Call]] returns false for ±0", () => {
383 assertStrictEquals(sameValue(0, -0), false);
386 it("[[Call]] returns true for -0", () => {
387 assertStrictEquals(sameValue(-0, -0), true);
390 it("[[Call]] returns true for nan", () => {
391 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
394 it("[[Call]] returns false for a primitive and its wrapped object", () => {
395 assertStrictEquals(sameValue(false, new Boolean(false)), false);
398 it("[[Construct]] throws an error", () => {
399 assertThrows(() => new sameValue(true, true));
402 describe(".length", () => {
403 it("[[Get]] returns the correct length", () => {
404 assertStrictEquals(sameValue
.length
, 2);
408 describe(".name", () => {
409 it("[[Get]] returns the correct name", () => {
410 assertStrictEquals(sameValue
.name
, "sameValue");
415 describe("sameValueZero", () => {
416 it("[[Call]] returns false for null 🆚 undefined", () => {
417 assertStrictEquals(sameValueZero(null, undefined), false);
420 it("[[Call]] returns false for null 🆚 an object", () => {
421 assertStrictEquals(sameValueZero(null, {}), false);
424 it("[[Call]] returns true for null 🆚 null", () => {
425 assertStrictEquals(sameValueZero(null, null), true);
428 it("[[Call]] returns false for two different objects", () => {
429 assertStrictEquals(sameValueZero({}, {}), false);
432 it("[[Call]] returns true for the same object", () => {
434 assertStrictEquals(sameValueZero(obj
, obj
), true);
437 it("[[Call]] returns true for ±0", () => {
438 assertStrictEquals(sameValueZero(0, -0), true);
441 it("[[Call]] returns true for -0", () => {
442 assertStrictEquals(sameValueZero(-0, -0), true);
445 it("[[Call]] returns true for nan", () => {
446 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
449 it("[[Call]] returns false for a primitive and its wrapped object", () => {
451 sameValueZero(false, new Boolean(false)),
456 it("[[Construct]] throws an error", () => {
457 assertThrows(() => new sameValueZero(true, true));
460 describe(".length", () => {
461 it("[[Get]] returns the correct length", () => {
462 assertStrictEquals(sameValueZero
.length
, 2);
466 describe(".name", () => {
467 it("[[Get]] returns the correct name", () => {
468 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
473 describe("toFunctionName", () => {
474 it("[[Call]] works with strings and no prefix", () => {
475 assertStrictEquals(toFunctionName("etaoin"), "etaoin");
478 it("[[Call]] works with objects and no prefix", () => {
489 it("[[Call]] works with descriptionless symbols and no prefix", () => {
490 assertStrictEquals(toFunctionName(Symbol()), "");
493 it("[[Call]] works with empty description symbols and no prefix", () => {
494 assertStrictEquals(toFunctionName(Symbol("")), "[]");
497 it("[[Call]] works with described symbols and no prefix", () => {
498 assertStrictEquals(toFunctionName(Symbol("etaoin")), "[etaoin]");
501 it("[[Call]] works with strings and a prefix", () => {
502 assertStrictEquals(toFunctionName("etaoin", "foo"), "foo etaoin");
505 it("[[Call]] works with objects and no prefix", () => {
516 it("[[Call]] works with descriptionless symbols and no prefix", () => {
517 assertStrictEquals(toFunctionName(Symbol(), "foo"), "foo ");
520 it("[[Call]] works with empty description symbols and no prefix", () => {
521 assertStrictEquals(toFunctionName(Symbol(""), "foo"), "foo []");
524 it("[[Call]] works with described symbols and no prefix", () => {
526 toFunctionName(Symbol("etaoin"), "foo"),
531 it("[[Construct]] throws an error", () => {
532 assertThrows(() => new toFunctionName(""));
535 describe(".length", () => {
536 it("[[Get]] returns the correct length", () => {
537 assertStrictEquals(toFunctionName
.length
, 1);
541 describe(".name", () => {
542 it("[[Get]] returns the correct name", () => {
551 describe("toIndex", () => {
552 it("[[Call]] returns an index", () => {
553 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
556 it("[[Call]] returns zero for a zerolike argument", () => {
557 assertStrictEquals(toIndex(NaN
), 0);
558 assertStrictEquals(toIndex("failure"), 0);
559 assertStrictEquals(toIndex(-0), 0);
562 it("[[Call]] rounds down to the nearest integer", () => {
563 assertStrictEquals(toIndex(0.25), 0);
564 assertStrictEquals(toIndex(1.1), 1);
567 it("[[Call]] throws when provided a negative number", () => {
568 assertThrows(() => toIndex(-1));
569 assertThrows(() => toIndex(-Infinity
));
572 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
573 assertThrows(() => toIndex(9007199254740992));
574 assertThrows(() => toIndex(Infinity
));
577 it("[[Construct]] throws an error", () => {
578 assertThrows(() => new toIndex(0));
581 describe(".length", () => {
582 it("[[Get]] returns the correct length", () => {
583 assertStrictEquals(toIndex
.length
, 1);
587 describe(".name", () => {
588 it("[[Get]] returns the correct name", () => {
589 assertStrictEquals(toIndex
.name
, "toIndex");
594 describe("toLength", () => {
595 it("[[Call]] returns a length", () => {
596 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
599 it("[[Call]] returns zero for a nan argument", () => {
600 assertStrictEquals(toLength(NaN
), 0);
601 assertStrictEquals(toLength("failure"), 0);
604 it("[[Call]] rounds down to the nearest integer", () => {
605 assertStrictEquals(toLength(0.25), 0);
606 assertStrictEquals(toLength(1.1), 1);
609 it("[[Call]] returns a result greater than or equal to zero", () => {
610 assertStrictEquals(toLength(-0), 0);
611 assertStrictEquals(toLength(-1), 0);
612 assertStrictEquals(toLength(-Infinity
), 0);
615 it("[[Call]] returns a result less than 2 ** 53", () => {
616 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
617 assertStrictEquals(toLength(Infinity
), 9007199254740991);
620 it("[[Construct]] throws an error", () => {
621 assertThrows(() => new toLength(0));
624 describe(".length", () => {
625 it("[[Get]] returns the correct length", () => {
626 assertStrictEquals(toLength
.length
, 1);
630 describe(".name", () => {
631 it("[[Get]] returns the correct name", () => {
632 assertStrictEquals(toLength
.name
, "toLength");
637 describe("toPrimitive", () => {
638 it("[[Call]] returns the argument when passed a primitive", () => {
639 const value
= Symbol();
640 assertStrictEquals(toPrimitive(value
), value
);
643 it("[[Call]] works with nullish values", () => {
644 assertStrictEquals(toPrimitive(null), null);
645 assertStrictEquals(toPrimitive(), void {});
648 it("[[Call]] calls ordinaryToPrimitive by default", () => {
649 const value
= Object
.assign(
657 assertStrictEquals(toPrimitive(value
), "success");
660 it("[[Call]] accepts a hint", () => {
661 const value
= Object
.assign(
672 assertStrictEquals(toPrimitive(value
, "string"), "success");
675 it("[[Call]] uses the exotic toPrimitive method if available", () => {
676 const value
= Object
.assign(
679 [Symbol
.toPrimitive
]() {
684 assertStrictEquals(toPrimitive(value
), "success");
687 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
688 const value
= Object
.assign(
691 [Symbol
.toPrimitive
](hint
) {
692 return hint
=== "string" ? "success" : "failure";
696 assertStrictEquals(toPrimitive(value
, "string"), "success");
699 it('[[Call]] passes a "default" hint by default', () => {
700 const value
= Object
.assign(
703 [Symbol
.toPrimitive
](hint
) {
704 return hint
=== "default" ? "success" : "failure";
708 assertStrictEquals(toPrimitive(value
), "success");
711 it("[[Call]] throws for an invalid hint", () => {
712 const value1
= Object
.assign(
715 [Symbol
.toPrimitive
]() {
720 const value2
= Object
.assign(
728 assertThrows(() => toPrimitive(value1
, "badhint"));
729 assertThrows(() => toPrimitive(value2
, "badhint"));
730 assertThrows(() => toPrimitive(true, "badhint"));
733 it("[[Construct]] throws an error", () => {
734 assertThrows(() => new toPrimitive(true));
737 describe(".length", () => {
738 it("[[Get]] returns the correct length", () => {
739 assertStrictEquals(toPrimitive
.length
, 1);
743 describe(".name", () => {
744 it("[[Get]] returns the correct name", () => {
745 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
750 describe("type", () => {
751 it('[[Call]] returns "null" for null', () => {
752 assertStrictEquals(type(null), "null");
755 it('[[Call]] returns "undefined" for undefined', () => {
756 assertStrictEquals(type(void {}), "undefined");
759 it('[[Call]] returns "object" for non‐callable objects', () => {
760 assertStrictEquals(type(Object
.create(null)), "object");
763 it('[[Call]] returns "object" for callable objects', () => {
764 assertStrictEquals(type(() => {}), "object");
767 it('[[Call]] returns "object" for constructable objects', () => {
768 assertStrictEquals(type(class {}), "object");
771 it("[[Construct]] throws an error", () => {
772 assertThrows(() => new type({}));
775 describe(".length", () => {
776 it("[[Get]] returns the correct length", () => {
777 assertStrictEquals(type
.length
, 1);
781 describe(".name", () => {
782 it("[[Get]] returns the correct name", () => {
783 assertStrictEquals(type
.name
, "type");