]>
Lady’s Gitweb - Pisces/blob - value.test.js
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(".name", () => {
210 it("[[Get]] returns the correct name", () => {
212 ordinaryToPrimitive
.name
,
213 "ordinaryToPrimitive",
219 describe("sameValue", () => {
220 it("[[Call]] returns false for null 🆚 undefined", () => {
221 assertStrictEquals(sameValue(null, undefined), false);
224 it("[[Call]] returns false for null 🆚 an object", () => {
225 assertStrictEquals(sameValue(null, {}), false);
228 it("[[Call]] returns true for null 🆚 null", () => {
229 assertStrictEquals(sameValue(null, null), true);
232 it("[[Call]] returns false for two different objects", () => {
233 assertStrictEquals(sameValue({}, {}), false);
236 it("[[Call]] returns true for the same object", () => {
238 assertStrictEquals(sameValue(obj
, obj
), true);
241 it("[[Call]] returns false for ±0", () => {
242 assertStrictEquals(sameValue(0, -0), false);
245 it("[[Call]] returns true for -0", () => {
246 assertStrictEquals(sameValue(-0, -0), true);
249 it("[[Call]] returns true for nan", () => {
250 assertStrictEquals(sameValue(0 / 0, 0 / 0), true);
253 it("[[Call]] returns false for a primitive and its wrapped object", () => {
254 assertStrictEquals(sameValue(false, new Boolean(false)), false);
257 it("[[Construct]] throws an error", () => {
258 assertThrows(() => new sameValue(true, true));
261 describe(".name", () => {
262 it("[[Get]] returns the correct name", () => {
263 assertStrictEquals(sameValue
.name
, "sameValue");
268 describe("sameValueZero", () => {
269 it("[[Call]] returns false for null 🆚 undefined", () => {
270 assertStrictEquals(sameValueZero(null, undefined), false);
273 it("[[Call]] returns false for null 🆚 an object", () => {
274 assertStrictEquals(sameValueZero(null, {}), false);
277 it("[[Call]] returns true for null 🆚 null", () => {
278 assertStrictEquals(sameValueZero(null, null), true);
281 it("[[Call]] returns false for two different objects", () => {
282 assertStrictEquals(sameValueZero({}, {}), false);
285 it("[[Call]] returns true for the same object", () => {
287 assertStrictEquals(sameValueZero(obj
, obj
), true);
290 it("[[Call]] returns true for ±0", () => {
291 assertStrictEquals(sameValueZero(0, -0), true);
294 it("[[Call]] returns true for -0", () => {
295 assertStrictEquals(sameValueZero(-0, -0), true);
298 it("[[Call]] returns true for nan", () => {
299 assertStrictEquals(sameValueZero(0 / 0, 0 / 0), true);
302 it("[[Call]] returns false for a primitive and its wrapped object", () => {
304 sameValueZero(false, new Boolean(false)),
309 it("[[Construct]] throws an error", () => {
310 assertThrows(() => new sameValueZero(true, true));
313 describe(".name", () => {
314 it("[[Get]] returns the correct name", () => {
315 assertStrictEquals(sameValueZero
.name
, "sameValueZero");
320 describe("toPrimitive", () => {
321 it("[[Call]] returns the argument when passed a primitive", () => {
322 const value
= Symbol();
323 assertStrictEquals(toPrimitive(value
), value
);
326 it("[[Call]] works with nullish values", () => {
327 assertStrictEquals(toPrimitive(null), null);
328 assertStrictEquals(toPrimitive(), void {});
331 it("[[Call]] calls ordinaryToPrimitive by default", () => {
332 const value
= Object
.assign(
340 assertStrictEquals(toPrimitive(value
), "success");
343 it("[[Call]] accepts a hint", () => {
344 const value
= Object
.assign(
355 assertStrictEquals(toPrimitive(value
, "string"), "success");
358 it("[[Call]] uses the exotic toPrimitive method if available", () => {
359 const value
= Object
.assign(
362 [Symbol
.toPrimitive
]() {
367 assertStrictEquals(toPrimitive(value
), "success");
370 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
371 const value
= Object
.assign(
374 [Symbol
.toPrimitive
](hint
) {
375 return hint
=== "string" ? "success" : "failure";
379 assertStrictEquals(toPrimitive(value
, "string"), "success");
382 it('[[Call]] passes a "default" hint by default', () => {
383 const value
= Object
.assign(
386 [Symbol
.toPrimitive
](hint
) {
387 return hint
=== "default" ? "success" : "failure";
391 assertStrictEquals(toPrimitive(value
), "success");
394 it("[[Call]] throws for an invalid hint", () => {
395 const value1
= Object
.assign(
398 [Symbol
.toPrimitive
]() {
403 const value2
= Object
.assign(
411 assertThrows(() => toPrimitive(value1
, "badhint"));
412 assertThrows(() => toPrimitive(value2
, "badhint"));
413 assertThrows(() => toPrimitive(true, "badhint"));
416 it("[[Construct]] throws an error", () => {
417 assertThrows(() => new toPrimitive(true));
420 describe(".name", () => {
421 it("[[Get]] returns the correct name", () => {
422 assertStrictEquals(toPrimitive
.name
, "toPrimitive");
427 describe("type", () => {
428 it('[[Call]] returns "null" for null', () => {
429 assertStrictEquals(type(null), "null");
432 it('[[Call]] returns "undefined" for undefined', () => {
433 assertStrictEquals(type(void {}), "undefined");
436 it('[[Call]] returns "object" for non‐callable objects', () => {
437 assertStrictEquals(type(Object
.create(null)), "object");
440 it('[[Call]] returns "object" for callable objects', () => {
441 assertStrictEquals(type(() => {}), "object");
444 it('[[Call]] returns "object" for constructable objects', () => {
445 assertStrictEquals(type(class {}), "object");
448 it("[[Construct]] throws an error", () => {
449 assertThrows(() => new type({}));
452 describe(".name", () => {
453 it("[[Get]] returns the correct name", () => {
454 assertStrictEquals(type
.name
, "type");
This page took 0.1449 seconds and 5 git commands to generate.