]> Lady’s Gitweb - Pisces/blobdiff - function.test.js
Minor refactors to numeric.js
[Pisces] / function.test.js
index 09b9f7e00160eb998a82f6714dbaece118aec180..a5c8311c13c3a1f861fd4c31d3c2c354eab84086 100644 (file)
@@ -1,15 +1,19 @@
-// ♓🌟 Piscēs ∷ function.test.js
-// ====================================================================
-//
-// Copyright © 2022–2023 Lady [@ Lady’s Computer].
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+// SPDX-FileCopyrightText: 2022, 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ function.test.js
+ *
+ * Copyright © 2022–2023, 2025 Lady [@ Ladys Computer].
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+ */
 
 import {
   assert,
   assertEquals,
+  assertNotStrictEquals,
   assertSpyCall,
   assertSpyCalls,
   assertStrictEquals,
@@ -337,8 +341,8 @@ describe("createArrowFunction", () => {
 
   it("[[Call]] returns a function with no prototype property", () => {
     assert(
-      !("prototype" in
-        createArrowFunction(function () {}, { prototype: {} })),
+      !("prototype"
+        in createArrowFunction(function () {}, { prototype: {} })),
     );
   });
 
@@ -429,8 +433,8 @@ describe("createCallableFunction", () => {
 
   it("[[Call]] returns a function with no prototype property", () => {
     assert(
-      !("prototype" in
-        createCallableFunction(function () {}, { prototype: {} })),
+      !("prototype"
+        in createCallableFunction(function () {}, { prototype: {} })),
     );
   });
 
@@ -469,9 +473,6 @@ describe("createIllegalConstructor", () => {
       Object.getPrototypeOf(constructor.prototype),
       Object.prototype,
     );
-    console.dir(
-      Object.getOwnPropertyDescriptors(constructor.prototype),
-    );
     assertEquals(
       constructor.prototype,
       Object.create(Object.prototype, {
@@ -712,6 +713,95 @@ describe("createProxyConstructor", () => {
     });
   });
 
+  describe("~is[[.name]]", () => {
+    it("[[GetOwnProperty]] defines the appropriate method", () => {
+      assertNotStrictEquals(
+        Object.getOwnPropertyDescriptor(
+          createProxyConstructor({}),
+          "isProxy",
+        ),
+        undefined,
+      );
+      assertNotStrictEquals(
+        Object.getOwnPropertyDescriptor(
+          createProxyConstructor({}, function Base() {}),
+          "isBaseProxy",
+        ),
+        undefined,
+      );
+      assertNotStrictEquals(
+        Object.getOwnPropertyDescriptor(
+          createProxyConstructor({}, function Bad() {}, undefined, {
+            name: "⸺",
+          }),
+          "is⸺",
+        ),
+        undefined,
+      );
+    });
+
+    it("[[GetOwnProperty]] has the correct descriptor", () => {
+      const proxyConstructor = createProxyConstructor({});
+      assertEquals(
+        Object.getOwnPropertyDescriptor(
+          proxyConstructor,
+          "isProxy",
+        ),
+        {
+          configurable: true,
+          enumerable: false,
+          value: proxyConstructor.isProxy,
+          writable: true,
+        },
+      );
+    });
+
+    it("[[Call]] returns true for created proxies", () => {
+      const proxyConstructor = createProxyConstructor({});
+      const proxy = new proxyConstructor();
+      assertStrictEquals(
+        proxyConstructor.isProxy(proxy),
+        true,
+      );
+    });
+
+    it("[[Call]] returns false for nonproxies", () => {
+      const constructor = function Base() {};
+      const proxyConstructor = createProxyConstructor({}, constructor);
+      assertStrictEquals(
+        proxyConstructor.isBaseProxy(new constructor()),
+        false,
+      );
+    });
+
+    it("[[Construct]] throws an error", () => {
+      const proxyConstructor = createProxyConstructor({});
+      assertThrows(() => new proxyConstructor.isProxy({}));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        const proxyConstructor = createProxyConstructor({});
+        assertStrictEquals(proxyConstructor.isProxy.length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        const proxyConstructor = createProxyConstructor({});
+        assertStrictEquals(proxyConstructor.isProxy.name, "isProxy");
+        const otherProxyConstructor = createProxyConstructor(
+          {},
+          function Base() {},
+        );
+        assertStrictEquals(
+          otherProxyConstructor.isBaseProxy.name,
+          "isBaseProxy",
+        );
+      });
+    });
+  });
+
   describe("~length", () => {
     it("[[GetOwnProperty]] has the correct descriptor", () => {
       assertEquals(
@@ -739,7 +829,7 @@ describe("createProxyConstructor", () => {
         {
           configurable: true,
           enumerable: false,
-          value: "ObjectProxy",
+          value: "Proxy",
           writable: false,
         },
       );
This page took 0.214528 seconds and 4 git commands to generate.