]>
Lady’s Gitweb - Pisces/blob - function.test.js
a9a5f3f3b07b51b8f5778ce5575591ff7a48e440
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"],
74 describe("call", () => {
75 it("[[Call]] calls with the provided this value", () => {
88 it("[[Call]] calls with the provided arguments", () => {
92 return [this, ...args
];
97 ["etaoin", "shrdlu", "cmfwyp"],
101 it("[[Call]] works with any arraylike third argument", () => {
105 return [this, ...args
];
115 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
120 describe("completesNormally", () => {
121 it("[[Call]] returns true for functions which complete normally", () => {
122 assertStrictEquals(completesNormally(() => {}), true);
125 it("[[Call]] returns false for functions which throw", () => {
127 completesNormally(() => {
134 it("[[Call]] throws when the argument is not callable", () => {
136 completesNormally(null);
140 it("[[Call]] throws when the argument is not provided", () => {
147 describe("construct", () => {
148 it("[[Call]] defaults to the constructor as the target", () => {
149 const constructor = class {};
151 Object
.getPrototypeOf(construct(
155 constructor.prototype,
159 it("[[Call]] constructs with the provided new target", () => {
160 const target = function () {};
173 it("[[Call]] constructs with the provided arguments", () => {
177 return [new.target
.value
, ...args
];
179 ["shrdlu", "cmfwyp"],
180 Object
.assign(function () {}, { value
: "etaoin" }),
182 ["etaoin", "shrdlu", "cmfwyp"],
186 it("[[Call]] works with any arraylike third argument", () => {
190 return [new.target
.value
, ...args
];
198 Object
.assign(function () {}, { value
: "etaoin" }),
200 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
205 describe("identity", () => {
206 it("[[Call]] returns what it is given", () => {
208 assertStrictEquals(identity(value
), value
);
211 it("[[Construct]] is constructable", () => {
213 assertStrictEquals(new identity(value
), value
);
216 it("[[Construct]] is subclassable", () => {
218 assertStrictEquals(new class extends identity
{}(value
), value
);
222 describe("isCallable", () => {
223 it("[[Call]] returns true for ordinary functions", () => {
224 assertStrictEquals(isCallable(function () {}), true);
227 it("[[Call]] returns true for arrow functions", () => {
228 assertStrictEquals(isCallable(() => {}), true);
231 it("[[Call]] returns true for generator functions", () => {
232 assertStrictEquals(isCallable(function* () {}), true);
235 it("[[Call]] returns true for classes", () => {
236 assertStrictEquals(isCallable(class {}), true);
239 it("[[Call]] returns true for builtin functions", () => {
240 assertStrictEquals(isCallable(Math
.ceil
), true);
243 it("[[Call]] returns true for getters", () => {
246 Object
.getOwnPropertyDescriptor({
256 it("[[Call]] returns true for setters", () => {
259 Object
.getOwnPropertyDescriptor({
269 it("[[Call]] returns false for null", () => {
270 assertStrictEquals(isCallable(null), false);
273 it("[[Call]] returns false for objects", () => {
274 assertStrictEquals(isCallable({}), false);
278 describe("isConstructor", () => {
279 it("[[Call]] returns true for ordinary functions", () => {
280 assertStrictEquals(isConstructor(function () {}), true);
283 it("[[Call]] returns false for arrow functions", () => {
284 assertStrictEquals(isConstructor(() => {}), false);
287 it("[[Call]] returns false for generator functions", () => {
288 assertStrictEquals(isConstructor(function* () {}), false);
291 it("[[Call]] returns true for classes", () => {
292 assertStrictEquals(isConstructor(class {}), true);
295 it("[[Call]] returns false for builtin functions", () => {
296 assertStrictEquals(isConstructor(Math
.ceil
), false);
299 it("[[Call]] returns false for getters", () => {
302 Object
.getOwnPropertyDescriptor({
312 it("[[Call]] returns false for setters", () => {
315 Object
.getOwnPropertyDescriptor({
325 it("[[Call]] returns false for null", () => {
326 assertStrictEquals(isConstructor(null), false);
329 it("[[Call]] returns false for objects", () => {
330 assertStrictEquals(isConstructor({}), false);
334 describe("makeCallable", () => {
335 it("[[Call]] transfers the first argument to this", () => {
341 ).call("fail", "pass"),
346 it("[[Call]] transfers the remaining arguments", () => {
350 return [this, ...args
];
352 ).call("failure", "etaoin", "shrdlu", "cmfwyp"),
353 ["etaoin", "shrdlu", "cmfwyp"],
358 describe("ordinaryHasInstance", () => {
359 it("[[Call]] walks the prototype chain", () => {
360 const constructor = class {
361 [Symbol
.hasInstance
]() {
368 new class extends constructor {}(),
This page took 0.07405 seconds and 3 git commands to generate.