]>
Lady’s Gitweb - Pisces/blob - value.test.js
d68ff653e091b9573b5e69b5526c791fdcc76f61
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";
41 describe("ASYNC_ITERATOR", () => {
42 it("[[Get]] is @@asyncIterator", () => {
43 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
47 describe("HAS_INSTANCE", () => {
48 it("[[Get]] is @@hasInstance", () => {
49 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
53 describe("IS_CONCAT_SPREADABLE", () => {
54 it("[[Get]] is @@isConcatSpreadable", () => {
57 Symbol
.isConcatSpreadable
,
62 describe("ITERATOR", () => {
63 it("[[Get]] is @@iterator", () => {
64 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
68 describe("MATCH", () => {
69 it("[[Get]] is @@match", () => {
70 assertStrictEquals(MATCH
, Symbol
.match
);
74 describe("MATCH_ALL", () => {
75 it("[[Get]] is @@matchAll", () => {
76 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
80 describe("NULL", () => {
81 it("[[Get]] is null", () => {
82 assertStrictEquals(NULL
, null);
86 describe("REPLACE", () => {
87 it("[[Get]] is @@replace", () => {
88 assertStrictEquals(REPLACE
, Symbol
.replace
);
92 describe("SPECIES", () => {
93 it("[[Get]] is @@species", () => {
94 assertStrictEquals(SPECIES
, Symbol
.species
);
98 describe("SPLIT", () => {
99 it("[[Get]] is @@split", () => {
100 assertStrictEquals(SPLIT
, Symbol
.split
);
104 describe("TO_PRIMITIVE", () => {
105 it("[[Get]] is @@toPrimitive", () => {
106 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
110 describe("TO_STRING_TAG", () => {
111 it("[[Get]] is @@toStringTag", () => {
112 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
116 describe("UNDEFINED", () => {
117 it("[[Get]] is undefined", () => {
118 assertStrictEquals(UNDEFINED
, void {});
122 describe("UNSCOPABLES", () => {
123 it("[[Get]] is @@unscopables", () => {
124 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
128 describe("lengthOfArraylike", () => {
129 it("[[Call]] returns the length", () => {
131 lengthOfArraylike({ length
: 9007199254740991 }),
136 it("[[Call]] returns a non·nan result", () => {
137 assertStrictEquals(lengthOfArraylike({ length
: NaN
}), 0);
138 assertStrictEquals(lengthOfArraylike({ length
: "failure" }), 0);
141 it("[[Call]] returns an integral result", () => {
142 assertStrictEquals(lengthOfArraylike({ length
: 0.25 }), 0);
143 assertStrictEquals(lengthOfArraylike({ length
: 1.1 }), 1);
146 it("[[Call]] returns a result greater than or equal to zero", () => {
147 assertStrictEquals(lengthOfArraylike({ length
: -0 }), 0);
148 assertStrictEquals(lengthOfArraylike({ length
: -1 }), 0);
149 assertStrictEquals(lengthOfArraylike({ length
: -Infinity
}), 0);
152 it("[[Call]] returns a result less than 2 ** 53", () => {
154 lengthOfArraylike({ length
: 9007199254740992 }),
158 lengthOfArraylike({ length
: Infinity
}),
163 it("[[Call]] does not require an object argument", () => {
164 assertStrictEquals(lengthOfArraylike("string"), 6);
165 assertStrictEquals(lengthOfArraylike(Symbol()), 0);
168 it("[[Construct]] throws an error", () => {
169 assertThrows(() => new lengthOfArraylike(""));
172 describe(".length", () => {
173 it("[[Get]] returns the correct length", () => {
174 assertStrictEquals(lengthOfArraylike
.length
, 1);
178 describe(".name", () => {
179 it("[[Get]] returns the correct name", () => {
180 assertStrictEquals(lengthOfArraylike
.name
, "lengthOfArraylike");
185 describe("ordinaryToPrimitive", () => {
186 it("[[Call]] prefers `valueOf` by default", () => {
195 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
196 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
199 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
208 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
211 it('[[Call]] prefers `toString` for a "string" hint', () => {
220 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
223 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
230 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
233 it("[[Call]] falls back to the other method if the first returns an object", () => {
239 return new String("failure");
242 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
245 it("[[Call]] throws an error if neither method is callable", () => {
250 assertThrows(() => ordinaryToPrimitive(obj
));
253 it("[[Call]] throws an error if neither method returns an object", () => {
256 return new String("failure");
259 return new String("failure");
262 assertThrows(() => ordinaryToPrimitive(obj
));
265 it("[[Construct]] throws an error", () => {
266 assertThrows(() => new ordinaryToPrimitive(""));
269 describe(".length", () => {
270 it("[[Get]] returns the correct length", () => {
271 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
275 describe(".name", () => {
276 it("[[Get]] returns the correct name", () => {
278 ordinaryToPrimitive
.name
,
279 "ordinaryToPrimitive",
285 describe("sameValue", () => {
286 it("[[Call]] returns false for null 🆚 undefined", () => {
287 assertStrictEquals(sameValue(null, undefined), false);
290 it("[[Call]] returns false for null 🆚 an object", () => {
291 assertStrictEquals(sameValue(null, {}), false);
294 it("[[Call]] returns true for null 🆚 null", () => {
295 assertStrictEquals(sameValue(null, null), true);
298 it("[[Call]] returns false for two different objects", () => {
299 assertStrictEquals(sameValue({}, {}), false);
302 it("[[Call]] returns true for the same object", () => {
304 assertStrictEquals(sameValue(obj
, obj
), true);
307 it("[[Call]] returns false for ±0", () => {
308 assertStrictEquals(sameValue(0, -0), false);
311 it("[[Call]] returns true for -0", () => {
312 assertStrictEquals(sameValue(-0, -0), true);
315 it("[[Call]] returns true for nan", () => {
316 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
319 it("[[Call]] returns false for a primitive and its wrapped object", () => {
320 assertStrictEquals(sameValue(false, new Boolean(false)), false);
323 it("[[Construct]] throws an error", () => {
324 assertThrows(() => new sameValue(true, true));
327 describe(".length", () => {
328 it("[[Get]] returns the correct length", () => {
329 assertStrictEquals(sameValue
.length
, 2);
333 describe(".name", () => {
334 it("[[Get]] returns the correct name", () => {
335 assertStrictEquals(sameValue
.name
, "sameValue");
340 describe("sameValueZero", () => {
341 it("[[Call]] returns false for null 🆚 undefined", () => {
342 assertStrictEquals(sameValueZero(null, undefined), false);
345 it("[[Call]] returns false for null 🆚 an object", () => {
346 assertStrictEquals(sameValueZero(null, {}), false);
349 it("[[Call]] returns true for null 🆚 null", () => {
350 assertStrictEquals(sameValueZero(null, null), true);
353 it("[[Call]] returns false for two different objects", () => {
354 assertStrictEquals(sameValueZero({}, {}), false);
357 it("[[Call]] returns true for the same object", () => {
359 assertStrictEquals(sameValueZero(obj
, obj
), true);
362 it("[[Call]] returns true for ±0", () => {
363 assertStrictEquals(sameValueZero(0, -0), true);
366 it("[[Call]] returns true for -0", () => {
367 assertStrictEquals(sameValueZero(-0, -0), true);
370 it("[[Call]] returns true for nan", () => {
371 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
374 it("[[Call]] returns false for a primitive and its wrapped object", () => {
376 sameValueZero(false, new Boolean(false)),
381 it("[[Construct]] throws an error", () => {
382 assertThrows(() => new sameValueZero(true, true));
385 describe(".length", () => {
386 it("[[Get]] returns the correct length", () => {
387 assertStrictEquals(sameValueZero
.length
, 2);
391 describe(".name", () => {
392 it("[[Get]] returns the correct name", () => {
393 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
398 describe("toIndex", () => {
399 it("[[Call]] returns an index", () => {
400 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
403 it("[[Call]] returns zero for a zerolike argument", () => {
404 assertStrictEquals(toIndex(NaN
), 0);
405 assertStrictEquals(toIndex("failure"), 0);
406 assertStrictEquals(toIndex(-0), 0);
409 it("[[Call]] rounds down to the nearest integer", () => {
410 assertStrictEquals(toIndex(0.25), 0);
411 assertStrictEquals(toIndex(1.1), 1);
414 it("[[Call]] throws when provided a negative number", () => {
415 assertThrows(() => toIndex(-1));
416 assertThrows(() => toIndex(-Infinity
));
419 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
420 assertThrows(() => toIndex(9007199254740992));
421 assertThrows(() => toIndex(Infinity
));
424 it("[[Construct]] throws an error", () => {
425 assertThrows(() => new toIndex(0));
428 describe(".length", () => {
429 it("[[Get]] returns the correct length", () => {
430 assertStrictEquals(toIndex
.length
, 1);
434 describe(".name", () => {
435 it("[[Get]] returns the correct name", () => {
436 assertStrictEquals(toIndex
.name
, "toIndex");
441 describe("toLength", () => {
442 it("[[Call]] returns a length", () => {
443 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
446 it("[[Call]] returns zero for a nan argument", () => {
447 assertStrictEquals(toLength(NaN
), 0);
448 assertStrictEquals(toLength("failure"), 0);
451 it("[[Call]] rounds down to the nearest integer", () => {
452 assertStrictEquals(toLength(0.25), 0);
453 assertStrictEquals(toLength(1.1), 1);
456 it("[[Call]] returns a result greater than or equal to zero", () => {
457 assertStrictEquals(toLength(-0), 0);
458 assertStrictEquals(toLength(-1), 0);
459 assertStrictEquals(toLength(-Infinity
), 0);
462 it("[[Call]] returns a result less than 2 ** 53", () => {
463 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
464 assertStrictEquals(toLength(Infinity
), 9007199254740991);
467 it("[[Construct]] throws an error", () => {
468 assertThrows(() => new toLength(0));
471 describe(".length", () => {
472 it("[[Get]] returns the correct length", () => {
473 assertStrictEquals(toLength
.length
, 1);
477 describe(".name", () => {
478 it("[[Get]] returns the correct name", () => {
479 assertStrictEquals(toLength
.name
, "toLength");
484 describe("toPrimitive", () => {
485 it("[[Call]] returns the argument when passed a primitive", () => {
486 const value
= Symbol();
487 assertStrictEquals(toPrimitive(value
), value
);
490 it("[[Call]] works with nullish values", () => {
491 assertStrictEquals(toPrimitive(null), null);
492 assertStrictEquals(toPrimitive(), void {});
495 it("[[Call]] calls ordinaryToPrimitive by default", () => {
496 const value
= Object
.assign(
504 assertStrictEquals(toPrimitive(value
), "success");
507 it("[[Call]] accepts a hint", () => {
508 const value
= Object
.assign(
519 assertStrictEquals(toPrimitive(value
, "string"), "success");
522 it("[[Call]] uses the exotic toPrimitive method if available", () => {
523 const value
= Object
.assign(
526 [Symbol
.toPrimitive
]() {
531 assertStrictEquals(toPrimitive(value
), "success");
534 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
535 const value
= Object
.assign(
538 [Symbol
.toPrimitive
](hint
) {
539 return hint
=== "string" ? "success" : "failure";
543 assertStrictEquals(toPrimitive(value
, "string"), "success");
546 it('[[Call]] passes a "default" hint by default', () => {
547 const value
= Object
.assign(
550 [Symbol
.toPrimitive
](hint
) {
551 return hint
=== "default" ? "success" : "failure";
555 assertStrictEquals(toPrimitive(value
), "success");
558 it("[[Call]] throws for an invalid hint", () => {
559 const value1
= Object
.assign(
562 [Symbol
.toPrimitive
]() {
567 const value2
= Object
.assign(
575 assertThrows(() => toPrimitive(value1
, "badhint"));
576 assertThrows(() => toPrimitive(value2
, "badhint"));
577 assertThrows(() => toPrimitive(true, "badhint"));
580 it("[[Construct]] throws an error", () => {
581 assertThrows(() => new toPrimitive(true));
584 describe(".length", () => {
585 it("[[Get]] returns the correct length", () => {
586 assertStrictEquals(toPrimitive
.length
, 1);
590 describe(".name", () => {
591 it("[[Get]] returns the correct name", () => {
592 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
597 describe("type", () => {
598 it('[[Call]] returns "null" for null', () => {
599 assertStrictEquals(type(null), "null");
602 it('[[Call]] returns "undefined" for undefined', () => {
603 assertStrictEquals(type(void {}), "undefined");
606 it('[[Call]] returns "object" for non‐callable objects', () => {
607 assertStrictEquals(type(Object
.create(null)), "object");
610 it('[[Call]] returns "object" for callable objects', () => {
611 assertStrictEquals(type(() => {}), "object");
614 it('[[Call]] returns "object" for constructable objects', () => {
615 assertStrictEquals(type(class {}), "object");
618 it("[[Construct]] throws an error", () => {
619 assertThrows(() => new type({}));
622 describe(".length", () => {
623 it("[[Get]] returns the correct length", () => {
624 assertStrictEquals(type
.length
, 1);
628 describe(".name", () => {
629 it("[[Get]] returns the correct name", () => {
630 assertStrictEquals(type
.name
, "type");
This page took 0.094123 seconds and 3 git commands to generate.