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
,
58 describe("ASYNC_ITERATOR", () => {
59 it("[[Get]] is @@asyncIterator", () => {
60 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
64 describe("HAS_INSTANCE", () => {
65 it("[[Get]] is @@hasInstance", () => {
66 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
70 describe("IS_CONCAT_SPREADABLE", () => {
71 it("[[Get]] is @@isConcatSpreadable", () => {
74 Symbol
.isConcatSpreadable
,
79 describe("ITERATOR", () => {
80 it("[[Get]] is @@iterator", () => {
81 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
85 describe("LN10", () => {
86 it("[[Get]] is ln(10)", () => {
87 assertStrictEquals(LN10
, Math
.LN10
);
91 describe("LN2", () => {
92 it("[[Get]] is ln(2)", () => {
93 assertStrictEquals(LN2
, Math
.LN2
);
97 describe("LOG10ℇ", () => {
98 it("[[Get]] is log10(ℇ)", () => {
99 assertStrictEquals(LOG10
ℇ, Math
.LOG10E
);
103 describe("LOG2ℇ", () => {
104 it("[[Get]] is log2(ℇ)", () => {
105 assertStrictEquals(LOG2
ℇ, Math
.LOG2E
);
109 describe("MATCH", () => {
110 it("[[Get]] is @@match", () => {
111 assertStrictEquals(MATCH
, Symbol
.match
);
115 describe("MATCH_ALL", () => {
116 it("[[Get]] is @@matchAll", () => {
117 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
121 describe("MAXIMUM_NUMBER", () => {
122 it("[[Get]] is the maximum number", () => {
123 assertStrictEquals(MAXIMUM_NUMBER
, Number
.MAX_VALUE
);
127 describe("MAXIMUM_SAFE_INTEGRAL_NUMBER", () => {
128 it("[[Get]] is the maximum safe integral number", () => {
130 MAXIMUM_SAFE_INTEGRAL_NUMBER
,
131 Number
.MAX_SAFE_INTEGER
,
136 describe("MINIMUM_NUMBER", () => {
137 it("[[Get]] is the minimum number", () => {
138 assertStrictEquals(MINIMUM_NUMBER
, Number
.MIN_VALUE
);
142 describe("MINIMUM_SAFE_INTEGRAL_NUMBER", () => {
143 it("[[Get]] is the minimum safe integral number", () => {
145 MINIMUM_SAFE_INTEGRAL_NUMBER
,
146 Number
.MIN_SAFE_INTEGER
,
151 describe("NAN", () => {
152 it("[[Get]] is nan", () => {
153 assertStrictEquals(NAN
, NaN
);
157 describe("NEGATIVE_INFINITY", () => {
158 it("[[Get]] is negative infinity", () => {
159 assertStrictEquals(NEGATIVE_INFINITY
, -Infinity
);
163 describe("NEGATIVE_ZERO", () => {
164 it("[[Get]] is negative zero", () => {
165 assertStrictEquals(NEGATIVE_ZERO
, -0);
169 describe("NULL", () => {
170 it("[[Get]] is null", () => {
171 assertStrictEquals(NULL
, null);
175 describe("POSITIVE_INFINITY", () => {
176 it("[[Get]] is negative infinity", () => {
177 assertStrictEquals(POSITIVE_INFINITY
, Infinity
);
181 describe("POSITIVE_ZERO", () => {
182 it("[[Get]] is positive zero", () => {
183 assertStrictEquals(POSITIVE_ZERO
, 0);
187 describe("RECIPROCAL_SQRT2", () => {
188 it("[[Get]] is sqrt(½)", () => {
189 assertStrictEquals(RECIPROCAL_SQRT2
, Math
.SQRT1_2
);
193 describe("REPLACE", () => {
194 it("[[Get]] is @@replace", () => {
195 assertStrictEquals(REPLACE
, Symbol
.replace
);
199 describe("SPECIES", () => {
200 it("[[Get]] is @@species", () => {
201 assertStrictEquals(SPECIES
, Symbol
.species
);
205 describe("SPLIT", () => {
206 it("[[Get]] is @@split", () => {
207 assertStrictEquals(SPLIT
, Symbol
.split
);
211 describe("SQRT2", () => {
212 it("[[Get]] is sqrt(2)", () => {
213 assertStrictEquals(SQRT2
, Math
.SQRT2
);
217 describe("TO_PRIMITIVE", () => {
218 it("[[Get]] is @@toPrimitive", () => {
219 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
223 describe("TO_STRING_TAG", () => {
224 it("[[Get]] is @@toStringTag", () => {
225 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
229 describe("UNDEFINED", () => {
230 it("[[Get]] is undefined", () => {
231 assertStrictEquals(UNDEFINED
, void {});
235 describe("UNSCOPABLES", () => {
236 it("[[Get]] is @@unscopables", () => {
237 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
241 describe("Ε", () => {
242 it("[[Get]] is ε", () => {
243 assertStrictEquals(Ε, Number
.EPSILON
);
247 describe("Π", () => {
248 it("[[Get]] is π", () => {
249 assertStrictEquals(Π, Math
.PI
);
253 describe("ℇ", () => {
254 it("[[Get]] is ℇ", () => {
255 assertStrictEquals(ℇ, Math
.E
);
259 describe("ordinaryToPrimitive", () => {
260 it("[[Call]] prefers `valueOf` by default", () => {
269 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
270 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
273 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
282 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
285 it('[[Call]] prefers `toString` for a "string" hint', () => {
294 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
297 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
304 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
307 it("[[Call]] falls back to the other method if the first returns an object", () => {
313 return new String("failure");
316 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
319 it("[[Call]] throws an error if neither method is callable", () => {
324 assertThrows(() => ordinaryToPrimitive(obj
));
327 it("[[Call]] throws an error if neither method returns an object", () => {
330 return new String("failure");
333 return new String("failure");
336 assertThrows(() => ordinaryToPrimitive(obj
));
339 it("[[Construct]] throws an error", () => {
340 assertThrows(() => new ordinaryToPrimitive(""));
343 describe(".length", () => {
344 it("[[Get]] returns the correct length", () => {
345 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
349 describe(".name", () => {
350 it("[[Get]] returns the correct name", () => {
352 ordinaryToPrimitive
.name
,
353 "ordinaryToPrimitive",
359 describe("sameValue", () => {
360 it("[[Call]] returns false for null 🆚 undefined", () => {
361 assertStrictEquals(sameValue(null, undefined), false);
364 it("[[Call]] returns false for null 🆚 an object", () => {
365 assertStrictEquals(sameValue(null, {}), false);
368 it("[[Call]] returns true for null 🆚 null", () => {
369 assertStrictEquals(sameValue(null, null), true);
372 it("[[Call]] returns false for two different objects", () => {
373 assertStrictEquals(sameValue({}, {}), false);
376 it("[[Call]] returns true for the same object", () => {
378 assertStrictEquals(sameValue(obj
, obj
), true);
381 it("[[Call]] returns false for ±0", () => {
382 assertStrictEquals(sameValue(0, -0), false);
385 it("[[Call]] returns true for -0", () => {
386 assertStrictEquals(sameValue(-0, -0), true);
389 it("[[Call]] returns true for nan", () => {
390 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
393 it("[[Call]] returns false for a primitive and its wrapped object", () => {
394 assertStrictEquals(sameValue(false, new Boolean(false)), false);
397 it("[[Construct]] throws an error", () => {
398 assertThrows(() => new sameValue(true, true));
401 describe(".length", () => {
402 it("[[Get]] returns the correct length", () => {
403 assertStrictEquals(sameValue
.length
, 2);
407 describe(".name", () => {
408 it("[[Get]] returns the correct name", () => {
409 assertStrictEquals(sameValue
.name
, "sameValue");
414 describe("sameValueZero", () => {
415 it("[[Call]] returns false for null 🆚 undefined", () => {
416 assertStrictEquals(sameValueZero(null, undefined), false);
419 it("[[Call]] returns false for null 🆚 an object", () => {
420 assertStrictEquals(sameValueZero(null, {}), false);
423 it("[[Call]] returns true for null 🆚 null", () => {
424 assertStrictEquals(sameValueZero(null, null), true);
427 it("[[Call]] returns false for two different objects", () => {
428 assertStrictEquals(sameValueZero({}, {}), false);
431 it("[[Call]] returns true for the same object", () => {
433 assertStrictEquals(sameValueZero(obj
, obj
), true);
436 it("[[Call]] returns true for ±0", () => {
437 assertStrictEquals(sameValueZero(0, -0), true);
440 it("[[Call]] returns true for -0", () => {
441 assertStrictEquals(sameValueZero(-0, -0), true);
444 it("[[Call]] returns true for nan", () => {
445 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
448 it("[[Call]] returns false for a primitive and its wrapped object", () => {
450 sameValueZero(false, new Boolean(false)),
455 it("[[Construct]] throws an error", () => {
456 assertThrows(() => new sameValueZero(true, true));
459 describe(".length", () => {
460 it("[[Get]] returns the correct length", () => {
461 assertStrictEquals(sameValueZero
.length
, 2);
465 describe(".name", () => {
466 it("[[Get]] returns the correct name", () => {
467 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
472 describe("toIndex", () => {
473 it("[[Call]] returns an index", () => {
474 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
477 it("[[Call]] returns zero for a zerolike argument", () => {
478 assertStrictEquals(toIndex(NaN
), 0);
479 assertStrictEquals(toIndex("failure"), 0);
480 assertStrictEquals(toIndex(-0), 0);
483 it("[[Call]] rounds down to the nearest integer", () => {
484 assertStrictEquals(toIndex(0.25), 0);
485 assertStrictEquals(toIndex(1.1), 1);
488 it("[[Call]] throws when provided a negative number", () => {
489 assertThrows(() => toIndex(-1));
490 assertThrows(() => toIndex(-Infinity
));
493 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
494 assertThrows(() => toIndex(9007199254740992));
495 assertThrows(() => toIndex(Infinity
));
498 it("[[Construct]] throws an error", () => {
499 assertThrows(() => new toIndex(0));
502 describe(".length", () => {
503 it("[[Get]] returns the correct length", () => {
504 assertStrictEquals(toIndex
.length
, 1);
508 describe(".name", () => {
509 it("[[Get]] returns the correct name", () => {
510 assertStrictEquals(toIndex
.name
, "toIndex");
515 describe("toLength", () => {
516 it("[[Call]] returns a length", () => {
517 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
520 it("[[Call]] returns zero for a nan argument", () => {
521 assertStrictEquals(toLength(NaN
), 0);
522 assertStrictEquals(toLength("failure"), 0);
525 it("[[Call]] rounds down to the nearest integer", () => {
526 assertStrictEquals(toLength(0.25), 0);
527 assertStrictEquals(toLength(1.1), 1);
530 it("[[Call]] returns a result greater than or equal to zero", () => {
531 assertStrictEquals(toLength(-0), 0);
532 assertStrictEquals(toLength(-1), 0);
533 assertStrictEquals(toLength(-Infinity
), 0);
536 it("[[Call]] returns a result less than 2 ** 53", () => {
537 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
538 assertStrictEquals(toLength(Infinity
), 9007199254740991);
541 it("[[Construct]] throws an error", () => {
542 assertThrows(() => new toLength(0));
545 describe(".length", () => {
546 it("[[Get]] returns the correct length", () => {
547 assertStrictEquals(toLength
.length
, 1);
551 describe(".name", () => {
552 it("[[Get]] returns the correct name", () => {
553 assertStrictEquals(toLength
.name
, "toLength");
558 describe("toPrimitive", () => {
559 it("[[Call]] returns the argument when passed a primitive", () => {
560 const value
= Symbol();
561 assertStrictEquals(toPrimitive(value
), value
);
564 it("[[Call]] works with nullish values", () => {
565 assertStrictEquals(toPrimitive(null), null);
566 assertStrictEquals(toPrimitive(), void {});
569 it("[[Call]] calls ordinaryToPrimitive by default", () => {
570 const value
= Object
.assign(
578 assertStrictEquals(toPrimitive(value
), "success");
581 it("[[Call]] accepts a hint", () => {
582 const value
= Object
.assign(
593 assertStrictEquals(toPrimitive(value
, "string"), "success");
596 it("[[Call]] uses the exotic toPrimitive method if available", () => {
597 const value
= Object
.assign(
600 [Symbol
.toPrimitive
]() {
605 assertStrictEquals(toPrimitive(value
), "success");
608 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
609 const value
= Object
.assign(
612 [Symbol
.toPrimitive
](hint
) {
613 return hint
=== "string" ? "success" : "failure";
617 assertStrictEquals(toPrimitive(value
, "string"), "success");
620 it('[[Call]] passes a "default" hint by default', () => {
621 const value
= Object
.assign(
624 [Symbol
.toPrimitive
](hint
) {
625 return hint
=== "default" ? "success" : "failure";
629 assertStrictEquals(toPrimitive(value
), "success");
632 it("[[Call]] throws for an invalid hint", () => {
633 const value1
= Object
.assign(
636 [Symbol
.toPrimitive
]() {
641 const value2
= Object
.assign(
649 assertThrows(() => toPrimitive(value1
, "badhint"));
650 assertThrows(() => toPrimitive(value2
, "badhint"));
651 assertThrows(() => toPrimitive(true, "badhint"));
654 it("[[Construct]] throws an error", () => {
655 assertThrows(() => new toPrimitive(true));
658 describe(".length", () => {
659 it("[[Get]] returns the correct length", () => {
660 assertStrictEquals(toPrimitive
.length
, 1);
664 describe(".name", () => {
665 it("[[Get]] returns the correct name", () => {
666 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
671 describe("type", () => {
672 it('[[Call]] returns "null" for null', () => {
673 assertStrictEquals(type(null), "null");
676 it('[[Call]] returns "undefined" for undefined', () => {
677 assertStrictEquals(type(void {}), "undefined");
680 it('[[Call]] returns "object" for non‐callable objects', () => {
681 assertStrictEquals(type(Object
.create(null)), "object");
684 it('[[Call]] returns "object" for callable objects', () => {
685 assertStrictEquals(type(() => {}), "object");
688 it('[[Call]] returns "object" for constructable objects', () => {
689 assertStrictEquals(type(class {}), "object");
692 it("[[Construct]] throws an error", () => {
693 assertThrows(() => new type({}));
696 describe(".length", () => {
697 it("[[Get]] returns the correct length", () => {
698 assertStrictEquals(type
.length
, 1);
702 describe(".name", () => {
703 it("[[Get]] returns the correct name", () => {
704 assertStrictEquals(type
.name
, "type");