]>
Lady’s Gitweb - Pisces/blob - value.test.js
88d727bc50bdb7d4fd2f41b37999f86152ec09ab
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";
40 describe("ASYNC_ITERATOR", () => {
41 it("[[Get]] is @@asyncIterator", () => {
42 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
46 describe("HAS_INSTANCE", () => {
47 it("[[Get]] is @@hasInstance", () => {
48 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
52 describe("IS_CONCAT_SPREADABLE", () => {
53 it("[[Get]] is @@isConcatSpreadable", () => {
56 Symbol
.isConcatSpreadable
,
61 describe("ITERATOR", () => {
62 it("[[Get]] is @@iterator", () => {
63 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
67 describe("MATCH", () => {
68 it("[[Get]] is @@match", () => {
69 assertStrictEquals(MATCH
, Symbol
.match
);
73 describe("MATCH_ALL", () => {
74 it("[[Get]] is @@matchAll", () => {
75 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
79 describe("NULL", () => {
80 it("[[Get]] is null", () => {
81 assertStrictEquals(NULL
, null);
85 describe("REPLACE", () => {
86 it("[[Get]] is @@replace", () => {
87 assertStrictEquals(REPLACE
, Symbol
.replace
);
91 describe("SPECIES", () => {
92 it("[[Get]] is @@species", () => {
93 assertStrictEquals(SPECIES
, Symbol
.species
);
97 describe("SPLIT", () => {
98 it("[[Get]] is @@split", () => {
99 assertStrictEquals(SPLIT
, Symbol
.split
);
103 describe("TO_PRIMITIVE", () => {
104 it("[[Get]] is @@toPrimitive", () => {
105 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
109 describe("TO_STRING_TAG", () => {
110 it("[[Get]] is @@toStringTag", () => {
111 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
115 describe("UNDEFINED", () => {
116 it("[[Get]] is undefined", () => {
117 assertStrictEquals(UNDEFINED
, void {});
121 describe("UNSCOPABLES", () => {
122 it("[[Get]] is @@unscopables", () => {
123 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
127 describe("ordinaryToPrimitive", () => {
128 it("[[Call]] prefers `valueOf` by default", () => {
137 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
138 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
141 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
150 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
153 it('[[Call]] prefers `toString` for a "string" hint', () => {
162 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
165 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
172 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
175 it("[[Call]] falls back to the other method if the first returns an object", () => {
181 return new String("failure");
184 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
187 it("[[Call]] throws an error if neither method is callable", () => {
192 assertThrows(() => ordinaryToPrimitive(obj
));
195 it("[[Call]] throws an error if neither method returns an object", () => {
198 return new String("failure");
201 return new String("failure");
204 assertThrows(() => ordinaryToPrimitive(obj
));
207 it("[[Construct]] throws an error", () => {
208 assertThrows(() => new ordinaryToPrimitive(""));
211 describe(".length", () => {
212 it("[[Get]] returns the correct length", () => {
213 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
217 describe(".name", () => {
218 it("[[Get]] returns the correct name", () => {
220 ordinaryToPrimitive
.name
,
221 "ordinaryToPrimitive",
227 describe("sameValue", () => {
228 it("[[Call]] returns false for null 🆚 undefined", () => {
229 assertStrictEquals(sameValue(null, undefined), false);
232 it("[[Call]] returns false for null 🆚 an object", () => {
233 assertStrictEquals(sameValue(null, {}), false);
236 it("[[Call]] returns true for null 🆚 null", () => {
237 assertStrictEquals(sameValue(null, null), true);
240 it("[[Call]] returns false for two different objects", () => {
241 assertStrictEquals(sameValue({}, {}), false);
244 it("[[Call]] returns true for the same object", () => {
246 assertStrictEquals(sameValue(obj
, obj
), true);
249 it("[[Call]] returns false for ±0", () => {
250 assertStrictEquals(sameValue(0, -0), false);
253 it("[[Call]] returns true for -0", () => {
254 assertStrictEquals(sameValue(-0, -0), true);
257 it("[[Call]] returns true for nan", () => {
258 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
261 it("[[Call]] returns false for a primitive and its wrapped object", () => {
262 assertStrictEquals(sameValue(false, new Boolean(false)), false);
265 it("[[Construct]] throws an error", () => {
266 assertThrows(() => new sameValue(true, true));
269 describe(".length", () => {
270 it("[[Get]] returns the correct length", () => {
271 assertStrictEquals(sameValue
.length
, 2);
275 describe(".name", () => {
276 it("[[Get]] returns the correct name", () => {
277 assertStrictEquals(sameValue
.name
, "sameValue");
282 describe("sameValueZero", () => {
283 it("[[Call]] returns false for null 🆚 undefined", () => {
284 assertStrictEquals(sameValueZero(null, undefined), false);
287 it("[[Call]] returns false for null 🆚 an object", () => {
288 assertStrictEquals(sameValueZero(null, {}), false);
291 it("[[Call]] returns true for null 🆚 null", () => {
292 assertStrictEquals(sameValueZero(null, null), true);
295 it("[[Call]] returns false for two different objects", () => {
296 assertStrictEquals(sameValueZero({}, {}), false);
299 it("[[Call]] returns true for the same object", () => {
301 assertStrictEquals(sameValueZero(obj
, obj
), true);
304 it("[[Call]] returns true for ±0", () => {
305 assertStrictEquals(sameValueZero(0, -0), true);
308 it("[[Call]] returns true for -0", () => {
309 assertStrictEquals(sameValueZero(-0, -0), true);
312 it("[[Call]] returns true for nan", () => {
313 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
316 it("[[Call]] returns false for a primitive and its wrapped object", () => {
318 sameValueZero(false, new Boolean(false)),
323 it("[[Construct]] throws an error", () => {
324 assertThrows(() => new sameValueZero(true, true));
327 describe(".length", () => {
328 it("[[Get]] returns the correct length", () => {
329 assertStrictEquals(sameValueZero
.length
, 2);
333 describe(".name", () => {
334 it("[[Get]] returns the correct name", () => {
335 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
340 describe("toIndex", () => {
341 it("[[Call]] returns an index", () => {
342 assertStrictEquals(toIndex(9007199254740991), 9007199254740991);
345 it("[[Call]] returns zero for a zerolike argument", () => {
346 assertStrictEquals(toIndex(NaN
), 0);
347 assertStrictEquals(toIndex("failure"), 0);
348 assertStrictEquals(toIndex(-0), 0);
351 it("[[Call]] rounds down to the nearest integer", () => {
352 assertStrictEquals(toIndex(0.25), 0);
353 assertStrictEquals(toIndex(1.1), 1);
356 it("[[Call]] throws when provided a negative number", () => {
357 assertThrows(() => toIndex(-1));
358 assertThrows(() => toIndex(-Infinity
));
361 it("[[Call]] throws when provided a number greater than or equal to 2 ** 53", () => {
362 assertThrows(() => toIndex(9007199254740992));
363 assertThrows(() => toIndex(Infinity
));
366 it("[[Construct]] throws an error", () => {
367 assertThrows(() => new toIndex(0));
370 describe(".length", () => {
371 it("[[Get]] returns the correct length", () => {
372 assertStrictEquals(toIndex
.length
, 1);
376 describe(".name", () => {
377 it("[[Get]] returns the correct name", () => {
378 assertStrictEquals(toIndex
.name
, "toIndex");
383 describe("toLength", () => {
384 it("[[Call]] returns a length", () => {
385 assertStrictEquals(toLength(9007199254740991), 9007199254740991);
388 it("[[Call]] returns zero for a nan argument", () => {
389 assertStrictEquals(toLength(NaN
), 0);
390 assertStrictEquals(toLength("failure"), 0);
393 it("[[Call]] rounds down to the nearest integer", () => {
394 assertStrictEquals(toLength(0.25), 0);
395 assertStrictEquals(toLength(1.1), 1);
398 it("[[Call]] returns a result greater than or equal to zero", () => {
399 assertStrictEquals(toLength(-0), 0);
400 assertStrictEquals(toLength(-1), 0);
401 assertStrictEquals(toLength(-Infinity
), 0);
404 it("[[Call]] returns a result less than 2 ** 53", () => {
405 assertStrictEquals(toLength(9007199254740992), 9007199254740991);
406 assertStrictEquals(toLength(Infinity
), 9007199254740991);
409 it("[[Construct]] throws an error", () => {
410 assertThrows(() => new toLength(0));
413 describe(".length", () => {
414 it("[[Get]] returns the correct length", () => {
415 assertStrictEquals(toLength
.length
, 1);
419 describe(".name", () => {
420 it("[[Get]] returns the correct name", () => {
421 assertStrictEquals(toLength
.name
, "toLength");
426 describe("toPrimitive", () => {
427 it("[[Call]] returns the argument when passed a primitive", () => {
428 const value
= Symbol();
429 assertStrictEquals(toPrimitive(value
), value
);
432 it("[[Call]] works with nullish values", () => {
433 assertStrictEquals(toPrimitive(null), null);
434 assertStrictEquals(toPrimitive(), void {});
437 it("[[Call]] calls ordinaryToPrimitive by default", () => {
438 const value
= Object
.assign(
446 assertStrictEquals(toPrimitive(value
), "success");
449 it("[[Call]] accepts a hint", () => {
450 const value
= Object
.assign(
461 assertStrictEquals(toPrimitive(value
, "string"), "success");
464 it("[[Call]] uses the exotic toPrimitive method if available", () => {
465 const value
= Object
.assign(
468 [Symbol
.toPrimitive
]() {
473 assertStrictEquals(toPrimitive(value
), "success");
476 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
477 const value
= Object
.assign(
480 [Symbol
.toPrimitive
](hint
) {
481 return hint
=== "string" ? "success" : "failure";
485 assertStrictEquals(toPrimitive(value
, "string"), "success");
488 it('[[Call]] passes a "default" hint by default', () => {
489 const value
= Object
.assign(
492 [Symbol
.toPrimitive
](hint
) {
493 return hint
=== "default" ? "success" : "failure";
497 assertStrictEquals(toPrimitive(value
), "success");
500 it("[[Call]] throws for an invalid hint", () => {
501 const value1
= Object
.assign(
504 [Symbol
.toPrimitive
]() {
509 const value2
= Object
.assign(
517 assertThrows(() => toPrimitive(value1
, "badhint"));
518 assertThrows(() => toPrimitive(value2
, "badhint"));
519 assertThrows(() => toPrimitive(true, "badhint"));
522 it("[[Construct]] throws an error", () => {
523 assertThrows(() => new toPrimitive(true));
526 describe(".length", () => {
527 it("[[Get]] returns the correct length", () => {
528 assertStrictEquals(toPrimitive
.length
, 1);
532 describe(".name", () => {
533 it("[[Get]] returns the correct name", () => {
534 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
539 describe("type", () => {
540 it('[[Call]] returns "null" for null', () => {
541 assertStrictEquals(type(null), "null");
544 it('[[Call]] returns "undefined" for undefined', () => {
545 assertStrictEquals(type(void {}), "undefined");
548 it('[[Call]] returns "object" for non‐callable objects', () => {
549 assertStrictEquals(type(Object
.create(null)), "object");
552 it('[[Call]] returns "object" for callable objects', () => {
553 assertStrictEquals(type(() => {}), "object");
556 it('[[Call]] returns "object" for constructable objects', () => {
557 assertStrictEquals(type(class {}), "object");
560 it("[[Construct]] throws an error", () => {
561 assertThrows(() => new type({}));
564 describe(".length", () => {
565 it("[[Get]] returns the correct length", () => {
566 assertStrictEquals(type
.length
, 1);
570 describe(".name", () => {
571 it("[[Get]] returns the correct name", () => {
572 assertStrictEquals(type
.name
, "type");
This page took 0.100713 seconds and 3 git commands to generate.