]>
Lady’s Gitweb - Pisces/blob - value.test.js
ae2b7d850793cdd139c7064124064e3ff6db687c
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";
38 describe("ASYNC_ITERATOR", () => {
39 it("[[Get]] is @@asyncIterator", () => {
40 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
44 describe("HAS_INSTANCE", () => {
45 it("[[Get]] is @@hasInstance", () => {
46 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
50 describe("IS_CONCAT_SPREADABLE", () => {
51 it("[[Get]] is @@isConcatSpreadable", () => {
54 Symbol
.isConcatSpreadable
,
59 describe("ITERATOR", () => {
60 it("[[Get]] is @@iterator", () => {
61 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
65 describe("MATCH", () => {
66 it("[[Get]] is @@match", () => {
67 assertStrictEquals(MATCH
, Symbol
.match
);
71 describe("MATCH_ALL", () => {
72 it("[[Get]] is @@matchAll", () => {
73 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
77 describe("NULL", () => {
78 it("[[Get]] is null", () => {
79 assertStrictEquals(NULL
, null);
83 describe("REPLACE", () => {
84 it("[[Get]] is @@replace", () => {
85 assertStrictEquals(REPLACE
, Symbol
.replace
);
89 describe("SPECIES", () => {
90 it("[[Get]] is @@species", () => {
91 assertStrictEquals(SPECIES
, Symbol
.species
);
95 describe("SPLIT", () => {
96 it("[[Get]] is @@split", () => {
97 assertStrictEquals(SPLIT
, Symbol
.split
);
101 describe("TO_PRIMITIVE", () => {
102 it("[[Get]] is @@toPrimitive", () => {
103 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
107 describe("TO_STRING_TAG", () => {
108 it("[[Get]] is @@toStringTag", () => {
109 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
113 describe("UNDEFINED", () => {
114 it("[[Get]] is undefined", () => {
115 assertStrictEquals(UNDEFINED
, void {});
119 describe("UNSCOPABLES", () => {
120 it("[[Get]] is @@unscopables", () => {
121 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
125 describe("ordinaryToPrimitive", () => {
126 it("[[Call]] prefers `valueOf` by default", () => {
135 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
136 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
139 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
148 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
151 it('[[Call]] prefers `toString` for a "string" hint', () => {
160 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
163 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
170 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
173 it("[[Call]] falls back to the other method if the first returns an object", () => {
179 return new String("failure");
182 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
185 it("[[Call]] throws an error if neither method is callable", () => {
190 assertThrows(() => ordinaryToPrimitive(obj
));
193 it("[[Call]] throws an error if neither method returns an object", () => {
196 return new String("failure");
199 return new String("failure");
202 assertThrows(() => ordinaryToPrimitive(obj
));
205 it("[[Construct]] throws an error", () => {
206 assertThrows(() => new ordinaryToPrimitive(""));
209 describe(".length", () => {
210 it("[[Get]] returns the correct length", () => {
211 assertStrictEquals(ordinaryToPrimitive
.length
, 2);
215 describe(".name", () => {
216 it("[[Get]] returns the correct name", () => {
218 ordinaryToPrimitive
.name
,
219 "ordinaryToPrimitive",
225 describe("sameValue", () => {
226 it("[[Call]] returns false for null 🆚 undefined", () => {
227 assertStrictEquals(sameValue(null, undefined), false);
230 it("[[Call]] returns false for null 🆚 an object", () => {
231 assertStrictEquals(sameValue(null, {}), false);
234 it("[[Call]] returns true for null 🆚 null", () => {
235 assertStrictEquals(sameValue(null, null), true);
238 it("[[Call]] returns false for two different objects", () => {
239 assertStrictEquals(sameValue({}, {}), false);
242 it("[[Call]] returns true for the same object", () => {
244 assertStrictEquals(sameValue(obj
, obj
), true);
247 it("[[Call]] returns false for ±0", () => {
248 assertStrictEquals(sameValue(0, -0), false);
251 it("[[Call]] returns true for -0", () => {
252 assertStrictEquals(sameValue(-0, -0), true);
255 it("[[Call]] returns true for nan", () => {
256 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
259 it("[[Call]] returns false for a primitive and its wrapped object", () => {
260 assertStrictEquals(sameValue(false, new Boolean(false)), false);
263 it("[[Construct]] throws an error", () => {
264 assertThrows(() => new sameValue(true, true));
267 describe(".length", () => {
268 it("[[Get]] returns the correct length", () => {
269 assertStrictEquals(sameValue
.length
, 2);
273 describe(".name", () => {
274 it("[[Get]] returns the correct name", () => {
275 assertStrictEquals(sameValue
.name
, "sameValue");
280 describe("sameValueZero", () => {
281 it("[[Call]] returns false for null 🆚 undefined", () => {
282 assertStrictEquals(sameValueZero(null, undefined), false);
285 it("[[Call]] returns false for null 🆚 an object", () => {
286 assertStrictEquals(sameValueZero(null, {}), false);
289 it("[[Call]] returns true for null 🆚 null", () => {
290 assertStrictEquals(sameValueZero(null, null), true);
293 it("[[Call]] returns false for two different objects", () => {
294 assertStrictEquals(sameValueZero({}, {}), false);
297 it("[[Call]] returns true for the same object", () => {
299 assertStrictEquals(sameValueZero(obj
, obj
), true);
302 it("[[Call]] returns true for ±0", () => {
303 assertStrictEquals(sameValueZero(0, -0), true);
306 it("[[Call]] returns true for -0", () => {
307 assertStrictEquals(sameValueZero(-0, -0), true);
310 it("[[Call]] returns true for nan", () => {
311 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
314 it("[[Call]] returns false for a primitive and its wrapped object", () => {
316 sameValueZero(false, new Boolean(false)),
321 it("[[Construct]] throws an error", () => {
322 assertThrows(() => new sameValueZero(true, true));
325 describe(".length", () => {
326 it("[[Get]] returns the correct length", () => {
327 assertStrictEquals(sameValueZero
.length
, 2);
331 describe(".name", () => {
332 it("[[Get]] returns the correct name", () => {
333 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
338 describe("toPrimitive", () => {
339 it("[[Call]] returns the argument when passed a primitive", () => {
340 const value
= Symbol();
341 assertStrictEquals(toPrimitive(value
), value
);
344 it("[[Call]] works with nullish values", () => {
345 assertStrictEquals(toPrimitive(null), null);
346 assertStrictEquals(toPrimitive(), void {});
349 it("[[Call]] calls ordinaryToPrimitive by default", () => {
350 const value
= Object
.assign(
358 assertStrictEquals(toPrimitive(value
), "success");
361 it("[[Call]] accepts a hint", () => {
362 const value
= Object
.assign(
373 assertStrictEquals(toPrimitive(value
, "string"), "success");
376 it("[[Call]] uses the exotic toPrimitive method if available", () => {
377 const value
= Object
.assign(
380 [Symbol
.toPrimitive
]() {
385 assertStrictEquals(toPrimitive(value
), "success");
388 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
389 const value
= Object
.assign(
392 [Symbol
.toPrimitive
](hint
) {
393 return hint
=== "string" ? "success" : "failure";
397 assertStrictEquals(toPrimitive(value
, "string"), "success");
400 it('[[Call]] passes a "default" hint by default', () => {
401 const value
= Object
.assign(
404 [Symbol
.toPrimitive
](hint
) {
405 return hint
=== "default" ? "success" : "failure";
409 assertStrictEquals(toPrimitive(value
), "success");
412 it("[[Call]] throws for an invalid hint", () => {
413 const value1
= Object
.assign(
416 [Symbol
.toPrimitive
]() {
421 const value2
= Object
.assign(
429 assertThrows(() => toPrimitive(value1
, "badhint"));
430 assertThrows(() => toPrimitive(value2
, "badhint"));
431 assertThrows(() => toPrimitive(true, "badhint"));
434 it("[[Construct]] throws an error", () => {
435 assertThrows(() => new toPrimitive(true));
438 describe(".length", () => {
439 it("[[Get]] returns the correct length", () => {
440 assertStrictEquals(toPrimitive
.length
, 1);
444 describe(".name", () => {
445 it("[[Get]] returns the correct name", () => {
446 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
451 describe("type", () => {
452 it('[[Call]] returns "null" for null', () => {
453 assertStrictEquals(type(null), "null");
456 it('[[Call]] returns "undefined" for undefined', () => {
457 assertStrictEquals(type(void {}), "undefined");
460 it('[[Call]] returns "object" for non‐callable objects', () => {
461 assertStrictEquals(type(Object
.create(null)), "object");
464 it('[[Call]] returns "object" for callable objects', () => {
465 assertStrictEquals(type(() => {}), "object");
468 it('[[Call]] returns "object" for constructable objects', () => {
469 assertStrictEquals(type(class {}), "object");
472 it("[[Construct]] throws an error", () => {
473 assertThrows(() => new type({}));
476 describe(".length", () => {
477 it("[[Get]] returns the correct length", () => {
478 assertStrictEquals(type
.length
, 1);
482 describe(".name", () => {
483 it("[[Get]] returns the correct name", () => {
484 assertStrictEquals(type
.name
, "type");
This page took 0.084436 seconds and 3 git commands to generate.