]> Lady’s Gitweb - Pisces/blobdiff - iterable.test.js
Define names and lengths for iterator functions
[Pisces] / iterable.test.js
index 0f7c9fcac0a96447695e0d0dd387df808c586f08..3651c6cb6917e254a940f4d09118aaedd38a0dfe 100644 (file)
@@ -1,11 +1,14 @@
-// ♓🌟 Piscēs ∷ iterable.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 ∷ iterable.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 {
   assertEquals,
@@ -126,6 +129,26 @@ describe("arrayIteratorFunction", () => {
       });
     });
 
+    it("[[Construct]] throws an error", () => {
+      const iterator = arrayIteratorFunction();
+      assertThrows(() => new iterator([]));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        assertStrictEquals(arrayIteratorFunction().length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        assertStrictEquals(
+          arrayIteratorFunction().name,
+          "values",
+        );
+      });
+    });
+
     describe("::next", () => {
       it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
         const iterator = arrayIteratorFunction(function () {});
@@ -253,6 +276,26 @@ describe("generatorIteratorFunction", () => {
       });
     });
 
+    it("[[Construct]] throws an error", () => {
+      const iterator = generatorIteratorFunction();
+      assertThrows(() => new iterator(function* () {}));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        assertStrictEquals(generatorIteratorFunction().length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        assertStrictEquals(
+          generatorIteratorFunction().name,
+          "yields",
+        );
+      });
+    });
+
     describe("::next", () => {
       it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
         const generator = function* () {
@@ -378,6 +421,26 @@ describe("mapIteratorFunction", () => {
       });
     });
 
+    it("[[Construct]] throws an error", () => {
+      const iterator = mapIteratorFunction();
+      assertThrows(() => new iterator(new Map()));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        assertStrictEquals(mapIteratorFunction().length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        assertStrictEquals(
+          mapIteratorFunction().name,
+          "entries",
+        );
+      });
+    });
+
     describe("::next", () => {
       it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
         const iterator = mapIteratorFunction(function () {});
@@ -493,6 +556,26 @@ describe("setIteratorFunction", () => {
       });
     });
 
+    it("[[Construct]] throws an error", () => {
+      const iterator = setIteratorFunction();
+      assertThrows(() => new iterator(new Set()));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        assertStrictEquals(setIteratorFunction().length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        assertStrictEquals(
+          setIteratorFunction().name,
+          "values",
+        );
+      });
+    });
+
     describe("::next", () => {
       it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
         const iterator = setIteratorFunction(function () {});
@@ -613,6 +696,26 @@ describe("stringIteratorFunction", () => {
       });
     });
 
+    it("[[Construct]] throws an error", () => {
+      const iterator = stringIteratorFunction();
+      assertThrows(() => new iterator(""));
+    });
+
+    describe(".length", () => {
+      it("[[Get]] returns the correct length", () => {
+        assertStrictEquals(stringIteratorFunction().length, 1);
+      });
+    });
+
+    describe(".name", () => {
+      it("[[Get]] returns the correct name", () => {
+        assertStrictEquals(
+          stringIteratorFunction().name,
+          "characters",
+        );
+      });
+    });
+
     describe("::next", () => {
       it("[[Call]] throws if there are values and the mapper is not a generator function", () => {
         const iterator = stringIteratorFunction(function () {});
This page took 0.316221 seconds and 4 git commands to generate.