]>
Lady’s Gitweb - Pisces/blob - function.test.js
17e77e24c58ae657a9c2bf025fd87a55def0043f
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/>.
15 } from "./dev-deps.js";
25 } from "./function.js";
27 describe("bind", () => {
28 it("[[Call]] binds this", () => {
41 it("[[Call]] binds arguments", () => {
45 return [this, ...args
];
49 ).call("failure", "cmfwyp"),
50 ["etaoin", "shrdlu", "cmfwyp"],
54 it("[[Call]] works with any arraylike third argument", () => {
58 return [this, ...args
];
66 ).call("failure", "cmfwyp"),
67 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
72 describe("call", () => {
73 it("[[Call]] calls with the provided this value", () => {
86 it("[[Call]] calls with the provided arguments", () => {
90 return [this, ...args
];
95 ["etaoin", "shrdlu", "cmfwyp"],
99 it("[[Call]] works with any arraylike third argument", () => {
103 return [this, ...args
];
113 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
118 describe("construct", () => {
119 it("[[Call]] defaults to the constructor as the target", () => {
120 const constructor = class {};
122 Object
.getPrototypeOf(construct(
126 constructor.prototype,
130 it("[[Call]] constructs with the provided new target", () => {
131 const target = function () {};
144 it("[[Call]] constructs with the provided arguments", () => {
148 return [new.target
.value
, ...args
];
150 ["shrdlu", "cmfwyp"],
151 Object
.assign(function () {}, { value
: "etaoin" }),
153 ["etaoin", "shrdlu", "cmfwyp"],
157 it("[[Call]] works with any arraylike third argument", () => {
161 return [new.target
.value
, ...args
];
169 Object
.assign(function () {}, { value
: "etaoin" }),
171 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
176 describe("identity", () => {
177 it("[[Call]] returns what it is given", () => {
179 assertStrictEquals(identity(value
), value
);
182 it("[[Construct]] is constructable", () => {
184 assertStrictEquals(new identity(value
), value
);
187 it("[[Construct]] is subclassable", () => {
189 assertStrictEquals(new class extends identity
{}(value
), value
);
193 describe("isCallable", () => {
194 it("[[Call]] returns true for ordinary functions", () => {
195 assertStrictEquals(isCallable(function () {}), true);
198 it("[[Call]] returns true for arrow functions", () => {
199 assertStrictEquals(isCallable(() => {}), true);
202 it("[[Call]] returns true for generator functions", () => {
203 assertStrictEquals(isCallable(function* () {}), true);
206 it("[[Call]] returns true for classes", () => {
207 assertStrictEquals(isCallable(class {}), true);
210 it("[[Call]] returns true for builtin functions", () => {
211 assertStrictEquals(isCallable(Math
.ceil
), true);
214 it("[[Call]] returns true for getters", () => {
217 Object
.getOwnPropertyDescriptor({
227 it("[[Call]] returns true for setters", () => {
230 Object
.getOwnPropertyDescriptor({
240 it("[[Call]] returns false for null", () => {
241 assertStrictEquals(isCallable(null), false);
244 it("[[Call]] returns false for objects", () => {
245 assertStrictEquals(isCallable({}), false);
249 describe("isConstructor", () => {
250 it("[[Call]] returns true for ordinary functions", () => {
251 assertStrictEquals(isConstructor(function () {}), true);
254 it("[[Call]] returns false for arrow functions", () => {
255 assertStrictEquals(isConstructor(() => {}), false);
258 it("[[Call]] returns false for generator functions", () => {
259 assertStrictEquals(isConstructor(function* () {}), false);
262 it("[[Call]] returns true for classes", () => {
263 assertStrictEquals(isConstructor(class {}), true);
266 it("[[Call]] returns false for builtin functions", () => {
267 assertStrictEquals(isConstructor(Math
.ceil
), false);
270 it("[[Call]] returns false for getters", () => {
273 Object
.getOwnPropertyDescriptor({
283 it("[[Call]] returns false for setters", () => {
286 Object
.getOwnPropertyDescriptor({
296 it("[[Call]] returns false for null", () => {
297 assertStrictEquals(isConstructor(null), false);
300 it("[[Call]] returns false for objects", () => {
301 assertStrictEquals(isConstructor({}), false);
305 describe("makeCallable", () => {
306 it("[[Call]] transfers the first argument to this", () => {
312 ).call("fail", "pass"),
317 it("[[Call]] transfers the remaining arguments", () => {
321 return [this, ...args
];
323 ).call("failure", "etaoin", "shrdlu", "cmfwyp"),
324 ["etaoin", "shrdlu", "cmfwyp"],
329 describe("ordinaryHasInstance", () => {
330 it("[[Call]] walks the prototype chain", () => {
331 const constructor = class {
332 [Symbol
.hasInstance
]() {
339 new class extends constructor {}(),
This page took 0.119716 seconds and 3 git commands to generate.