]>
Lady’s Gitweb - Pisces/blob - function.test.js
e9286624b895a35c4a439c119f56760f558a6f00
1 // ♓🌟 Piscēs ∷ function.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";
27 } from "./function.js";
29 describe("bind", () => {
30 it("[[Call]] binds this", () => {
43 it("[[Call]] binds arguments", () => {
47 return [this, ...args
];
51 ).call("failure", "cmfwyp"),
52 ["etaoin", "shrdlu", "cmfwyp"],
56 it("[[Call]] works with any arraylike third argument", () => {
60 return [this, ...args
];
68 ).call("failure", "cmfwyp"),
69 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
73 describe(".name", () => {
74 it("[[Get]] returns the correct name", () => {
75 assertStrictEquals(bind
.name
, "bind");
80 describe("call", () => {
81 it("[[Call]] calls with the provided this value", () => {
94 it("[[Call]] calls with the provided arguments", () => {
98 return [this, ...args
];
101 ["shrdlu", "cmfwyp"],
103 ["etaoin", "shrdlu", "cmfwyp"],
107 it("[[Call]] works with any arraylike third argument", () => {
111 return [this, ...args
];
121 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
125 describe(".name", () => {
126 it("[[Get]] returns the correct name", () => {
127 assertStrictEquals(call
.name
, "call");
132 describe("completesNormally", () => {
133 it("[[Call]] returns true for functions which complete normally", () => {
134 assertStrictEquals(completesNormally(() => {}), true);
137 it("[[Call]] returns false for functions which throw", () => {
139 completesNormally(() => {
146 it("[[Call]] throws when the argument is not callable", () => {
148 completesNormally(null);
152 it("[[Call]] throws when the argument is not provided", () => {
158 describe(".name", () => {
159 it("[[Get]] returns the correct name", () => {
160 assertStrictEquals(completesNormally
.name
, "completesNormally");
165 describe("construct", () => {
166 it("[[Call]] defaults to the constructor as the target", () => {
167 const constructor = class {};
169 Object
.getPrototypeOf(construct(
173 constructor.prototype,
177 it("[[Call]] constructs with the provided new target", () => {
178 const target = function () {};
191 it("[[Call]] constructs with the provided arguments", () => {
195 return [new.target
.value
, ...args
];
197 ["shrdlu", "cmfwyp"],
198 Object
.assign(function () {}, { value
: "etaoin" }),
200 ["etaoin", "shrdlu", "cmfwyp"],
204 it("[[Call]] works with any arraylike third argument", () => {
208 return [new.target
.value
, ...args
];
216 Object
.assign(function () {}, { value
: "etaoin" }),
218 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
222 describe(".name", () => {
223 it("[[Get]] returns the correct name", () => {
224 assertStrictEquals(construct
.name
, "construct");
229 describe("identity", () => {
230 it("[[Call]] returns what it is given", () => {
232 assertStrictEquals(identity(value
), value
);
235 it("[[Construct]] is constructable", () => {
237 assertStrictEquals(new identity(value
), value
);
240 it("[[Construct]] is subclassable", () => {
242 assertStrictEquals(new class extends identity
{}(value
), value
);
245 describe(".name", () => {
246 it("[[Get]] returns the correct name", () => {
247 assertStrictEquals(identity
.name
, "identity");
252 describe("isCallable", () => {
253 it("[[Call]] returns true for ordinary functions", () => {
254 assertStrictEquals(isCallable(function () {}), true);
257 it("[[Call]] returns true for arrow functions", () => {
258 assertStrictEquals(isCallable(() => {}), true);
261 it("[[Call]] returns true for generator functions", () => {
262 assertStrictEquals(isCallable(function* () {}), true);
265 it("[[Call]] returns true for classes", () => {
266 assertStrictEquals(isCallable(class {}), true);
269 it("[[Call]] returns true for builtin functions", () => {
270 assertStrictEquals(isCallable(Math
.ceil
), true);
273 it("[[Call]] returns true for getters", () => {
276 Object
.getOwnPropertyDescriptor({
286 it("[[Call]] returns true for setters", () => {
289 Object
.getOwnPropertyDescriptor({
299 it("[[Call]] returns false for null", () => {
300 assertStrictEquals(isCallable(null), false);
303 it("[[Call]] returns false for objects", () => {
304 assertStrictEquals(isCallable({}), false);
307 describe(".name", () => {
308 it("[[Get]] returns the correct name", () => {
309 assertStrictEquals(isCallable
.name
, "isCallable");
314 describe("isConstructor", () => {
315 it("[[Call]] returns true for ordinary functions", () => {
316 assertStrictEquals(isConstructor(function () {}), true);
319 it("[[Call]] returns false for arrow functions", () => {
320 assertStrictEquals(isConstructor(() => {}), false);
323 it("[[Call]] returns false for generator functions", () => {
324 assertStrictEquals(isConstructor(function* () {}), false);
327 it("[[Call]] returns true for classes", () => {
328 assertStrictEquals(isConstructor(class {}), true);
331 it("[[Call]] returns false for builtin functions", () => {
332 assertStrictEquals(isConstructor(Math
.ceil
), false);
335 it("[[Call]] returns false for getters", () => {
338 Object
.getOwnPropertyDescriptor({
348 it("[[Call]] returns false for setters", () => {
351 Object
.getOwnPropertyDescriptor({
361 it("[[Call]] returns false for null", () => {
362 assertStrictEquals(isConstructor(null), false);
365 it("[[Call]] returns false for objects", () => {
366 assertStrictEquals(isConstructor({}), false);
369 describe(".name", () => {
370 it("[[Get]] returns the correct name", () => {
371 assertStrictEquals(isConstructor
.name
, "isConstructor");
376 describe("makeCallable", () => {
377 it("[[Call]] transfers the first argument to this", () => {
383 ).call("fail", "pass"),
388 it("[[Call]] transfers the remaining arguments", () => {
392 return [this, ...args
];
394 ).call("failure", "etaoin", "shrdlu", "cmfwyp"),
395 ["etaoin", "shrdlu", "cmfwyp"],
399 describe(".name", () => {
400 it("[[Get]] returns the correct name", () => {
401 assertStrictEquals(makeCallable
.name
, "makeCallable");
406 describe("ordinaryHasInstance", () => {
407 it("[[Call]] walks the prototype chain", () => {
408 const constructor = class {
409 [Symbol
.hasInstance
]() {
416 new class extends constructor {}(),
422 describe(".name", () => {
423 it("[[Get]] returns the correct name", () => {
425 ordinaryHasInstance
.name
,
426 "ordinaryHasInstance",
This page took 0.076081 seconds and 3 git commands to generate.