]> Lady’s Gitweb - Pisces/blobdiff - symbol.test.js
Define names and lengths for iterator functions
[Pisces] / symbol.test.js
index bedcc72218473d5b8606b9fda7e82006dec2174d..22bc58e91a069346ca65e8501c1b685a32cbcaa0 100644 (file)
@@ -1,11 +1,14 @@
-// ♓🌟 Piscēs ∷ symbol.test.js
-// ====================================================================
-//
-// Copyright © 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: 2023, 2025 Lady <https://www.ladys.computer/about/#lady>
+// SPDX-License-Identifier: MPL-2.0
+/**
+ * ⁌ ♓🧩 Piscēs ∷ symbol.test.js
+ *
+ * Copyright © 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 {
   assertStrictEquals,
@@ -13,7 +16,11 @@ import {
   describe,
   it,
 } from "./dev-deps.js";
-import { getSymbolDescription } from "./symbol.js";
+import {
+  getSymbolDescription,
+  symbolToString,
+  symbolValue,
+} from "./symbol.js";
 
 describe("getSymbolDescription", () => {
   it("[[Call]] returns undefined when the symbol has no description", () => {
@@ -31,14 +38,16 @@ describe("getSymbolDescription", () => {
     );
   });
 
-  it("[[Call]] returns the empty string when the symbol has an empty description", () => {
-    assertStrictEquals(getSymbolDescription(Symbol("")), "");
-  });
-
   it("[[Construct]] throws an error", () => {
     assertThrows(() => new getSymbolDescription(Symbol()));
   });
 
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(getSymbolDescription.length, 1);
+    });
+  });
+
   describe(".name", () => {
     it("[[Get]] returns the correct name", () => {
       assertStrictEquals(
@@ -48,3 +57,86 @@ describe("getSymbolDescription", () => {
     });
   });
 });
+
+describe("symbolToString", () => {
+  it('[[Call]] returns "Symbol()" when the symbol has no description', () => {
+    assertStrictEquals(symbolToString(Symbol()), "Symbol()");
+  });
+
+  it('[[Call]] returns "Symbol()" when the symbol has an empty description', () => {
+    assertStrictEquals(symbolToString(Symbol("")), "Symbol()");
+  });
+
+  it('[[Call]] returns "Symbol()" wrapping the description', () => {
+    assertStrictEquals(
+      symbolToString(Symbol("etaoin")),
+      "Symbol(etaoin)",
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new symbolToString(Symbol()));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(symbolToString.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        symbolToString.name,
+        "symbolToString",
+      );
+    });
+  });
+});
+
+describe("symbolValue", () => {
+  it("[[Call]] returns the value of a symbol", () => {
+    const symbol = Symbol();
+    assertStrictEquals(symbolValue(symbol), symbol);
+  });
+
+  it("[[Call]] returns the value of a symbol wrapper", () => {
+    const symbol = Symbol();
+    assertStrictEquals(symbolValue(new Object(symbol)), symbol);
+  });
+
+  it("[[Call]] returns the value of a symbol subclass", () => {
+    class SymbolExtension extends Symbol {
+      constructor(symbol) {
+        return Object.setPrototypeOf(
+          new Object(symbol),
+          SymbolExtension.prototype,
+        );
+      }
+    }
+    const symbol = Symbol();
+    assertStrictEquals(
+      symbolValue(new SymbolExtension(symbol)),
+      symbol,
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new symbolValue(Symbol()));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(symbolValue.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        symbolValue.name,
+        "symbolValue",
+      );
+    });
+  });
+});
This page took 0.184202 seconds and 4 git commands to generate.