]>
Lady’s Gitweb - Pisces/blob - value.test.js
1 // ♓🌟 Piscēs ∷ value.test.js
2 // ====================================================================
4 // Copyright © 2022 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";
27 describe("NULL", () => {
28 it("[[Get]] is null", () => {
29 assertStrictEquals(NULL
, null);
33 describe("UNDEFINED", () => {
34 it("[[Get]] is undefined", () => {
35 assertStrictEquals(UNDEFINED
, void {});
39 describe("ordinaryToPrimitive", () => {
40 it("[[Call]] prefers `valueOf` by default", () => {
49 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
50 assertStrictEquals(ordinaryToPrimitive(obj
, "default"), "success");
53 it('[[Call]] prefers `valueOf` for a "number" hint', () => {
62 assertStrictEquals(ordinaryToPrimitive(obj
, "number"), "success");
65 it('[[Call]] prefers `toString` for a "string" hint', () => {
74 assertStrictEquals(ordinaryToPrimitive(obj
, "string"), "success");
77 it("[[Call]] falls back to the other method if the first isn’t callable", () => {
84 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
87 it("[[Call]] falls back to the other method if the first returns an object", () => {
93 return new String("failure");
96 assertStrictEquals(ordinaryToPrimitive(obj
), "success");
99 it("[[Call]] throws an error if neither method is callable", () => {
104 assertThrows(() => ordinaryToPrimitive(obj
));
107 it("[[Call]] throws an error if neither method returns an object", () => {
110 return new String("failure");
113 return new String("failure");
116 assertThrows(() => ordinaryToPrimitive(obj
));
120 describe("sameValue", () => {
121 it("[[Call]] returns false for null 🆚 undefined", () => {
122 assert(!sameValue(null, void {}));
125 it("[[Call]] returns false for null 🆚 an object", () => {
126 assert(!sameValue(null, {}));
129 it("[[Call]] returns true for null 🆚 null", () => {
130 assert(sameValue(null, null));
133 it("[[Call]] returns false for two different objects", () => {
134 assert(!sameValue({}, {}));
137 it("[[Call]] returns true for the same object", () => {
139 assert(sameValue(obj
, obj
));
142 it("[[Call]] returns false for ±0", () => {
143 assert(!sameValue(0, -0));
146 it("[[Call]] returns true for -0", () => {
147 assert(sameValue(-0, -0));
150 it("[[Call]] returns true for nan", () => {
151 assert(sameValue(0 / 0, 0 / 0));
154 it("[[Call]] returns false for a primitive and its wrapped object", () => {
155 assert(!sameValue(false, new Boolean(false)));
159 describe("sameValueZero", () => {
160 it("[[Call]] returns false for null 🆚 undefined", () => {
161 assert(!sameValueZero(null, void {}));
164 it("[[Call]] returns false for null 🆚 an object", () => {
165 assert(!sameValueZero(null, {}));
168 it("[[Call]] returns true for null 🆚 null", () => {
169 assert(sameValueZero(null, null));
172 it("[[Call]] returns false for two different objects", () => {
173 assert(!sameValueZero({}, {}));
176 it("[[Call]] returns true for the same object", () => {
178 assert(sameValueZero(obj
, obj
));
181 it("[[Call]] returns true for ±0", () => {
182 assert(sameValueZero(0, -0));
185 it("[[Call]] returns true for -0", () => {
186 assert(sameValueZero(-0, -0));
189 it("[[Call]] returns true for nan", () => {
190 assert(sameValueZero(0 / 0, 0 / 0));
193 it("[[Call]] returns false for a primitive and its wrapped object", () => {
194 assert(!sameValueZero(false, new Boolean(false)));
198 describe("toPrimitive", () => {
199 it("[[Call]] returns the argument when passed a primitive", () => {
200 const value
= Symbol();
201 assertStrictEquals(toPrimitive(value
), value
);
204 it("[[Call]] works with nullish values", () => {
205 assertStrictEquals(toPrimitive(null), null);
206 assertStrictEquals(toPrimitive(), void {});
209 it("[[Call]] calls ordinaryToPrimitive by default", () => {
210 const value
= Object
.assign(
218 assertStrictEquals(toPrimitive(value
), "success");
221 it("[[Call]] accepts a hint", () => {
222 const value
= Object
.assign(
233 assertStrictEquals(toPrimitive(value
, "string"), "success");
236 it("[[Call]] uses the exotic toPrimitive method if available", () => {
237 const value
= Object
.assign(
240 [Symbol
.toPrimitive
]() {
245 assertStrictEquals(toPrimitive(value
), "success");
248 it("[[Call]] passes the hint to the exotic toPrimitive", () => {
249 const value
= Object
.assign(
252 [Symbol
.toPrimitive
](hint
) {
253 return hint
=== "string" ? "success" : "failure";
257 assertStrictEquals(toPrimitive(value
, "string"), "success");
260 it('[[Call]] passes a "default" hint by default', () => {
261 const value
= Object
.assign(
264 [Symbol
.toPrimitive
](hint
) {
265 return hint
=== "default" ? "success" : "failure";
269 assertStrictEquals(toPrimitive(value
, "default"), "success");
272 it("[[Call]] throws for an invalid hint", () => {
273 const value1
= Object
.assign(
276 [Symbol
.toPrimitive
]() {
281 const value2
= Object
.assign(
289 assertThrows(() => toPrimitive(value1
, "badhint"));
290 assertThrows(() => toPrimitive(value2
, "badhint"));
291 assertThrows(() => toPrimitive(true, "badhint"));
295 describe("type", () => {
296 it('[[Call]] returns "null" for null', () => {
297 assertStrictEquals(type(null), "null");
300 it('[[Call]] returns "undefined" for undefined', () => {
301 assertStrictEquals(type(void {}), "undefined");
304 it('[[Call]] returns "object" for non‐callable objects', () => {
305 assertStrictEquals(type(Object
.create(null)), "object");
308 it('[[Call]] returns "object" for callable objects', () => {
309 assertStrictEquals(type(() => {}), "object");
312 it('[[Call]] returns "object" for constructable objects', () => {
313 assertStrictEquals(type(class {}), "object");
This page took 0.247172 seconds and 5 git commands to generate.