]>
Lady’s Gitweb - Pisces/blob - function.test.js
1 // ♓🌟 Piscēs ∷ function.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";
26 } from "./function.js";
28 describe("bind", () => {
29 it("[[Call]] binds this", () => {
42 it("[[Call]] binds arguments", () => {
46 return [this, ...args
];
50 ).call("failure", "cmfwyp"),
51 ["etaoin", "shrdlu", "cmfwyp"],
55 it("[[Call]] works with any arraylike third argument", () => {
59 return [this, ...args
];
67 ).call("failure", "cmfwyp"),
68 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
73 describe("call", () => {
74 it("[[Call]] calls with the provided this value", () => {
87 it("[[Call]] calls with the provided arguments", () => {
91 return [this, ...args
];
96 ["etaoin", "shrdlu", "cmfwyp"],
100 it("[[Call]] works with any arraylike third argument", () => {
104 return [this, ...args
];
114 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
119 describe("construct", () => {
120 it("[[Call]] defaults to the constructor as the target", () => {
121 const constructor = class {};
123 Object
.getPrototypeOf(construct(
127 constructor.prototype,
131 it("[[Call]] constructs with the provided new target", () => {
132 const target = function () {};
145 it("[[Call]] constructs with the provided arguments", () => {
149 return [new.target
.value
, ...args
];
151 ["shrdlu", "cmfwyp"],
152 Object
.assign(function () {}, { value
: "etaoin" }),
154 ["etaoin", "shrdlu", "cmfwyp"],
158 it("[[Call]] works with any arraylike third argument", () => {
162 return [new.target
.value
, ...args
];
170 Object
.assign(function () {}, { value
: "etaoin" }),
172 ["etaoin", undefined, "shrdlu", undefined, "cmfwyp"],
177 describe("identity", () => {
178 it("[[Call]] returns what it is given", () => {
180 assertStrictEquals(identity(value
), value
);
183 it("[[Construct]] is constructable", () => {
185 assertStrictEquals(new identity(value
), value
);
188 it("[[Construct]] is subclassable", () => {
190 assertStrictEquals(new class extends identity
{}(value
), value
);
194 describe("isCallable", () => {
195 it("[[Call]] returns true for ordinary functions", () => {
196 assert(isCallable(function () {}));
199 it("[[Call]] returns true for arrow functions", () => {
200 assert(isCallable(() => {}));
203 it("[[Call]] returns true for generator functions", () => {
204 assert(isCallable(function* () {}));
207 it("[[Call]] returns true for classes", () => {
208 assert(isCallable(class {}));
211 it("[[Call]] returns true for builtin functions", () => {
212 assert(isCallable(Math
.ceil
));
215 it("[[Call]] returns false for null", () => {
216 assert(!isCallable(null));
219 it("[[Call]] returns false for objects", () => {
220 assert(!isCallable({}));
224 describe("isConstructor", () => {
225 it("[[Call]] returns true for ordinary functions", () => {
226 assert(isConstructor(function () {}));
229 it("[[Call]] returns false for arrow functions", () => {
230 assert(!isConstructor(() => {}));
233 it("[[Call]] returns false for generator functions", () => {
234 assert(!isConstructor(function* () {}));
237 it("[[Call]] returns true for classes", () => {
238 assert(isConstructor(class {}));
241 it("[[Call]] returns false for builtin functions", () => {
242 assert(!isConstructor(Math
.ceil
));
245 it("[[Call]] returns false for null", () => {
246 assert(!isConstructor(null));
249 it("[[Call]] returns false for objects", () => {
250 assert(!isConstructor({}));
254 describe("makeCallable", () => {
255 it("[[Call]] transfers the first argument to this", () => {
261 ).call("fail", "pass"),
266 it("[[Call]] transfers the remaining arguments", () => {
270 return [this, ...args
];
272 ).call("failure", "etaoin", "shrdlu", "cmfwyp"),
273 ["etaoin", "shrdlu", "cmfwyp"],
278 describe("ordinaryHasInstance", () => {
279 it("[[Call]] walks the prototype chain", () => {
280 const constructor = class {
281 [Symbol
.hasInstance
]() {
288 new class extends constructor {}(),
This page took 0.130194 seconds and 5 git commands to generate.