]>
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/>.
16 } from "./dev-deps.js";
39 describe("ASYNC_ITERATOR", () => {
40 it("[[Get]] is @@asyncIterator", () => {
41 assertStrictEquals(ASYNC_ITERATOR
, Symbol
.asyncIterator
);
45 describe("HAS_INSTANCE", () => {
46 it("[[Get]] is @@hasInstance", () => {
47 assertStrictEquals(HAS_INSTANCE
, Symbol
.hasInstance
);
51 describe("IS_CONCAT_SPREADABLE", () => {
52 it("[[Get]] is @@isConcatSpreadable", () => {
55 Symbol
.isConcatSpreadable
,
60 describe("ITERATOR", () => {
61 it("[[Get]] is @@iterator", () => {
62 assertStrictEquals(ITERATOR
, Symbol
.iterator
);
66 describe("MATCH", () => {
67 it("[[Get]] is @@match", () => {
68 assertStrictEquals(MATCH
, Symbol
.match
);
72 describe("MATCH_ALL", () => {
73 it("[[Get]] is @@matchAll", () => {
74 assertStrictEquals(MATCH_ALL
, Symbol
.matchAll
);
78 describe("NULL", () => {
79 it("[[Get]] is null", () => {
80 assertStrictEquals(NULL
, null);
84 describe("REPLACE", () => {
85 it("[[Get]] is @@replace", () => {
86 assertStrictEquals(REPLACE
, Symbol
.replace
);
90 describe("SPECIES", () => {
91 it("[[Get]] is @@species", () => {
92 assertStrictEquals(SPECIES
, Symbol
.species
);
96 describe("SPLIT", () => {
97 it("[[Get]] is @@split", () => {
98 assertStrictEquals(SPLIT
, Symbol
.split
);
102 describe("TO_PRIMITIVE", () => {
103 it("[[Get]] is @@toPrimitive", () => {
104 assertStrictEquals(TO_PRIMITIVE
, Symbol
.toPrimitive
);
108 describe("TO_STRING_TAG", () => {
109 it("[[Get]] is @@toStringTag", () => {
110 assertStrictEquals(TO_STRING_TAG
, Symbol
.toStringTag
);
114 describe("UNDEFINED", () => {
115 it("[[Get]] is undefined", () => {
116 assertStrictEquals(UNDEFINED
, void {});
120 describe("UNSCOPABLES", () => {
121 it("[[Get]] is @@unscopables", () => {
122 assertStrictEquals(UNSCOPABLES
, Symbol
.unscopables
);
126 describe("ordinaryToPrimitive", () => {
127 it("[[Call]] prefers `valueOf` by default", () => {
136 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
137 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
140 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
149 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
152 it('[[Call]] prefers `toString` for a "string" hint', () => {
161 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
164 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
171 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
174 it("[[Call]] falls back to the other method if the first returns an object", () => {
180 return new String("failure");
183 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
186 it("[[Call]] throws an error if neither method is callable", () => {
191 assertThrows(() => ordinaryToPrimitive(obj
));
194 it("[[Call]] throws an error if neither method returns an object", () => {
197 return new String("failure");
200 return new String("failure");
203 assertThrows(() => ordinaryToPrimitive(obj
));
207 describe("sameValue", () => {
208 it("[[Call]] returns false for null 🆚 undefined", () => {
209 assert(!sameValue(null, void {}));
212 it("[[Call]] returns false for null 🆚 an object", () => {
213 assert(!sameValue(null, {}));
216 it("[[Call]] returns true for null 🆚 null", () => {
217 assert(sameValue(null, null));
220 it("[[Call]] returns false for two different objects", () => {
221 assert(!sameValue({}, {}));
224 it("[[Call]] returns true for the same object", () => {
226 assert(sameValue(obj
, obj
));
229 it("[[Call]] returns false for ±0", () => {
230 assert(!sameValue(0, -0));
233 it("[[Call]] returns true for -0", () => {
234 assert(sameValue(-0, -0));
237 it("[[Call]] returns true for nan", () => {
238 assert(sameValue(0 / 0, 0 / 0));
241 it("[[Call]] returns false for a primitive and its wrapped object", () => {
242 assert(!sameValue(false, new Boolean(false)));
246 describe("sameValueZero", () => {
247 it("[[Call]] returns false for null 🆚 undefined", () => {
248 assert(!sameValueZero(null, void {}));
251 it("[[Call]] returns false for null 🆚 an object", () => {
252 assert(!sameValueZero(null, {}));
255 it("[[Call]] returns true for null 🆚 null", () => {
256 assert(sameValueZero(null, null));
259 it("[[Call]] returns false for two different objects", () => {
260 assert(!sameValueZero({}, {}));
263 it("[[Call]] returns true for the same object", () => {
265 assert(sameValueZero(obj
, obj
));
268 it("[[Call]] returns true for ±0", () => {
269 assert(sameValueZero(0, -0));
272 it("[[Call]] returns true for -0", () => {
273 assert(sameValueZero(-0, -0));
276 it("[[Call]] returns true for nan", () => {
277 assert(sameValueZero(0 / 0, 0 / 0));
280 it("[[Call]] returns false for a primitive and its wrapped object", () => {
281 assert(!sameValueZero(false, new Boolean(false)));
285 describe("toPrimitive", () => {
286 it("[[Call]] returns the argument when passed a primitive", () => {
287 const value
= Symbol();
288 assertStrictEquals(toPrimitive(value
), value
);
291 it("[[Call]] works with nullish values", () => {
292 assertStrictEquals(toPrimitive(null), null);
293 assertStrictEquals(toPrimitive(), void {});
296 it("[[Call]] calls ordinaryToPrimitive by default", () => {
297 const value
= Object
.assign(
305 assertStrictEquals(toPrimitive(value
), "success");
308 it("[[Call]] accepts a hint", () => {
309 const value
= Object
.assign(
320 assertStrictEquals(toPrimitive(value
, "string"), "success");
323 it("[[Call]] uses the exotic toPrimitive method if available", () => {
324 const value
= Object
.assign(
327 [Symbol
.toPrimitive
]() {
332 assertStrictEquals(toPrimitive(value
), "success");
335 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
336 const value
= Object
.assign(
339 [Symbol
.toPrimitive
](hint
) {
340 return hint
=== "string" ? "success" : "failure";
344 assertStrictEquals(toPrimitive(value
, "string"), "success");
347 it('[[Call]] passes a "default" hint by default', () => {
348 const value
= Object
.assign(
351 [Symbol
.toPrimitive
](hint
) {
352 return hint
=== "default" ? "success" : "failure";
356 assertStrictEquals(toPrimitive(value
, "default"), "success");
359 it("[[Call]] throws for an invalid hint", () => {
360 const value1
= Object
.assign(
363 [Symbol
.toPrimitive
]() {
368 const value2
= Object
.assign(
376 assertThrows(() => toPrimitive(value1
, "badhint"));
377 assertThrows(() => toPrimitive(value2
, "badhint"));
378 assertThrows(() => toPrimitive(true, "badhint"));
382 describe("type", () => {
383 it('[[Call]] returns "null" for null', () => {
384 assertStrictEquals(type(null), "null");
387 it('[[Call]] returns "undefined" for undefined', () => {
388 assertStrictEquals(type(void {}), "undefined");
391 it('[[Call]] returns "object" for non‐callable objects', () => {
392 assertStrictEquals(type(Object
.create(null)), "object");
395 it('[[Call]] returns "object" for callable objects', () => {
396 assertStrictEquals(type(() => {}), "object");
399 it('[[Call]] returns "object" for constructable objects', () => {
400 assertStrictEquals(type(class {}), "object");
This page took 0.171477 seconds and 5 git commands to generate.